作者 yangfu

我提交的机会

... ... @@ -34,4 +34,7 @@ net_im_app_key ="9c5410602597a7fe367aeeebd8210262"
user_center_url ="http://suplus-ucenter-dev.fjmaimaimai.com"
user_center_salt ="rsF0pL!6DwjBO735"
user_center_app_key ="39aefef9e22744a3b2d2d3791824ae7b"
user_center_app_secret ="cykbjnfqgctn"
\ No newline at end of file
user_center_app_secret ="cykbjnfqgctn"
#Html5
h5_host = "https://web-open.fjmaimaimai.com"
\ No newline at end of file
... ...
... ... @@ -252,14 +252,14 @@ func (this *ChanceController) ChanceStatistics() {
msg = protocol.NewReturnResponse(chance.ChanceStatistics(header, request))
}
//MyChance 我的机会
//@router /myChance [post]
func (this *ChanceController) MyChance() {
//MySubmitChance 我提交的机会
//@router /mySubmitChance [post]
func (this *ChanceController) MySubmitChance() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MyChanceRequest
var request *protocol.MySubmitChanceRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
... ... @@ -270,5 +270,5 @@ func (this *ChanceController) MyChance() {
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.MyChance(header, request))
msg = protocol.NewReturnResponse(chance.MySubmitChance(header, request))
}
... ...
... ... @@ -2,7 +2,9 @@ package utils
import (
"errors"
"fmt"
"reflect"
"strings"
)
// 此函数将指定的结构体成员值更新到结构体中
... ... @@ -41,3 +43,18 @@ func SetStructValueByType(s interface{}, columnType string, columnValue interfac
}
return nil
}
func JoinInts(ids []int, spilt string) string {
var idStrings []string = make([]string, len(ids))
for i := 0; i < len(ids); i++ {
idStrings[i] = fmt.Sprintf("%v", ids[i])
}
return strings.Join(idStrings, spilt)
}
func JoinInt8s(ids []int8, spilt string) string {
var idStrings []string = make([]string, len(ids))
for i := 0; i < len(ids); i++ {
idStrings[i] = fmt.Sprintf("%v", ids[i])
}
return strings.Join(idStrings, spilt)
}
... ...
... ... @@ -90,26 +90,25 @@ func DeleteChance(id int64) (err error) {
return
}
//我的机会列表
func GetChanceMyChance(uid, cid int64, reviewStatus int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,speechs,videos
from (
select id,user_id,create_at,source_content from chance
where user_id=? and company_id=? and review_status =? and (?=0 or id>?)
where user_id=? and company_id=? and review_status in (?) and (?=0 or id>?)
order by create_at desc
limit ?
) a left JOIN chance_data b on a.id =b.chance_id`
sqlCount := `select count(0) from (
select id,user_id,create_at,source_content from chance
where user_id=? and company_id=? and review_status =?
where user_id=? and company_id=? and review_status in (?)
order by create_at desc
) a left JOIN chance_data b on a.id =b.chance_id`
if err = utils.ExecuteQueryOne(&total, sqlCount, uid, cid, reviewStatus); err != nil {
if err = utils.ExecuteQueryOne(&total, sqlCount, uid, cid, utils.JoinInt8s(reviewStatus, ",")); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql, uid, cid, reviewStatus, lastId, lastId, pageSize); err != nil {
if err = utils.ExecuteQueryAll(v, sql, uid, cid, utils.JoinInt8s(reviewStatus, ","), lastId, lastId, pageSize); err != nil {
return
}
}
... ...
package protocol
import "opp/models"
import (
"opp/models"
"time"
)
//机会审核
//审核对象
... ... @@ -164,7 +167,32 @@ type ChanceTotalItem struct {
}
/*MyChance 我的机会*/
type MyChanceRequest struct {
}
type MyChanceResponse struct {
type MySubmitChanceRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
ReviewStatus int8 `json:"reviewStatus"` //审核状态
}
type MySubmitChanceResponse struct {
List []ChanceItem `json:"list"`
Total int `json:"total"`
}
//我的机会列表
type ChanceItemOrm struct {
Id int64 `orm:"column(id)"`
Uid int64 `orm:"column(user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
SourceContent string `orm:"column(source_content)"`
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
}
type ChanceItem struct {
Id int64 `json:"id"`
CreateTime int64 `json:"createTime"`
Provider *BaseUserInfo `json:"provider"`
FormList []*Form `json:"formList" valid:"Required"`
Speechs []Speech `json:"speechs"`
Pictures []Picture `json:"pictures"`
Videos []Video `json:"videos"`
}
... ...
... ... @@ -113,6 +113,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "MySubmitChance",
Router: `/mySubmitChance`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceStatistics",
Router: `/statistics`,
AllowHTTPMethods: []string{"post"},
... ...
package agg
import (
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/models"
"opp/protocol"
)
//我的机会
func MyChanceStatic(header *protocol.RequestHeader, reviewStatus ...int8) (total int, err error) {
var ()
if total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, reviewStatus, 0, 0, nil); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
return
}
... ...
... ... @@ -587,9 +587,48 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
return
}
//我的机会
func MyChance(header *protocol.RequestHeader, request *protocol.MyChanceRequest) (rsp *protocol.MyChanceResponse, err error) {
var ()
rsp = &protocol.MyChanceResponse{}
//我提交的机会
func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitChanceRequest) (rsp *protocol.MySubmitChanceResponse, err error) {
var (
myChances []protocol.ChanceItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {
log.Error(err)
return
}
rsp = &protocol.MySubmitChanceResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
item := protocol.ChanceItem{
Id: chance.Id,
Provider: provider,
CreateTime: chance.CreateTime.Unix(),
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
rsp.List = append(rsp.List, item)
}
return
}
func jsonUnmarshal(jsonData string, v interface{}) {
if len(jsonData) == 0 {
return
}
if e := json.Unmarshal([]byte(jsonData), v); e != nil {
log.Error("json.unmarshal error data:", jsonData, e)
}
}
... ...
... ... @@ -362,13 +362,42 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
//用户中心-统计信息
func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatisticsRequest) (rsp *protocol.UserStatisticsResponse, err error) {
var (
flag int64
flag int64
total int
)
rsp = &protocol.UserStatisticsResponse{}
isMark := func(v int64) bool {
if flag != v {
return false
}
return (request.TypeTotal & v) > 0
}
for flag = 1; flag < (1 << 20); flag = flag << 1 {
total = 0
if isMark(protocol.MyCommitChance) {
if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusAuditging, protocol.ReviewStatusReturn, protocol.ReviewStatusPass); err != nil {
log.Error(err)
}
}
if isMark(protocol.MyCommitChanceWait) {
if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusAuditging); err != nil {
log.Error(err)
}
}
if isMark(protocol.MyAuditChanceReturn) {
if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusReturn); err != nil {
log.Error(err)
}
}
if isMark(protocol.MyCommitChancePass) {
if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusPass); err != nil {
log.Error(err)
}
}
if flag&request.TypeTotal > 0 {
rsp.Totals = append(rsp.Totals, protocol.TypeTotalItem{
Type: flag,
Type: flag,
Total: total,
})
}
}
... ...