|
@@ -6,6 +6,8 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/gogf/gf/database/gdb"
|
|
|
"github.com/lin-jim-leon/kuaishou/open/merchant"
|
|
|
+ "reflect"
|
|
|
+ "sort"
|
|
|
"youngmini_server/app/dao"
|
|
|
"youngmini_server/app/model"
|
|
|
"youngmini_server/app/model/youngee_talent_model"
|
|
@@ -45,123 +47,123 @@ func GetSelectionList(r *ghttp.Request) *TalentHttpResult {
|
|
|
|
|
|
pageIndex := r.GetQueryInt("idx", -1)
|
|
|
cntPerPage := r.GetQueryInt("cnt", -1)
|
|
|
- //platform := r.Get("platform")
|
|
|
- //secForm := r.Get("secform")
|
|
|
- //taskForm := r.Get("taskform")
|
|
|
- //categoryForm := r.Get("categoryform")
|
|
|
- //searchValue := r.Get("searchvalue")
|
|
|
- //if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
|
|
|
- // return &TalentHttpResult{Code: -1, Msg: "参数错误"}
|
|
|
- //}
|
|
|
- //
|
|
|
- //// 如果有领样形式的过滤条件,则将过滤条件保存于secFormList
|
|
|
- //var secFormList []interface{}
|
|
|
- //if secForm != nil {
|
|
|
- // if reflect.TypeOf(secForm).Kind() != reflect.Slice {
|
|
|
- // return &TalentHttpResult{Code: -2, Msg: "搜索条件领样形式错误"}
|
|
|
- // }
|
|
|
- //
|
|
|
- // secFormList = make([]interface{}, 0)
|
|
|
- // secFormList = secForm.([]interface{})
|
|
|
- //}
|
|
|
- //
|
|
|
- //// 如果有任务形式的过滤条件,则将过滤条件保存于taskFormList
|
|
|
- //var taskFormList []interface{}
|
|
|
- //if taskForm != nil {
|
|
|
- // if reflect.TypeOf(taskForm).Kind() != reflect.Slice {
|
|
|
- // return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
|
|
|
- // }
|
|
|
- //
|
|
|
- // taskFormList = make([]interface{}, 0)
|
|
|
- // taskFormList = taskForm.([]interface{})
|
|
|
- //}
|
|
|
- //
|
|
|
- //// 如果有商品类目的过滤条件,则将过滤条件保存于categoryFormList
|
|
|
- //var categoryFormList []interface{}
|
|
|
- //if categoryForm != nil {
|
|
|
- // if reflect.TypeOf(categoryForm).Kind() != reflect.Slice {
|
|
|
- // return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
|
|
|
- // }
|
|
|
- //
|
|
|
- // categoryFormList = make([]interface{}, 0)
|
|
|
- // categoryFormList = categoryForm.([]interface{})
|
|
|
- //}
|
|
|
-
|
|
|
- // 如果有平台的过滤条件,则将平台列表保存于platformList 弃用
|
|
|
- /* var platformList []interface{}
|
|
|
- if platform != nil {
|
|
|
- if reflect.TypeOf(platform).Kind() != reflect.Slice {
|
|
|
- return &TalentHttpResult{Code: -2, Msg: "搜索条件平台类型错误"}
|
|
|
- }
|
|
|
+ //排序字段
|
|
|
+ sortField := r.GetString("sortField", "") //根据哪个字段排序
|
|
|
+ orderTag := r.GetQueryInt("sortOrder", -1) //1降序,0升序
|
|
|
+ //领样和悬赏条件
|
|
|
+ secForm := r.Get("secform")
|
|
|
+ taskForm := r.Get("taskform")
|
|
|
+ //任务上线时间
|
|
|
+ createTime := r.Get("createTime")
|
|
|
+ //商品类目 智能家居、食品饮料等20种
|
|
|
+ categoryForm := r.Get("categoryform")
|
|
|
+ //搜索条件
|
|
|
+ searchValue := r.Get("searchvalue")
|
|
|
+
|
|
|
+ // 如果有领样形式的过滤条件,则将过滤条件保存于secFormList
|
|
|
+ var secFormList []interface{}
|
|
|
+ if secForm != nil {
|
|
|
+ if reflect.TypeOf(secForm).Kind() != reflect.Slice {
|
|
|
+ return &TalentHttpResult{Code: -2, Msg: "搜索条件领样形式错误"}
|
|
|
+ }
|
|
|
+
|
|
|
+ secFormList = make([]interface{}, 0)
|
|
|
+ secFormList = secForm.([]interface{})
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果有任务形式的过滤条件,则将过滤条件保存于taskFormList
|
|
|
+ var taskFormList []interface{}
|
|
|
+ if taskForm != nil {
|
|
|
+ if reflect.TypeOf(taskForm).Kind() != reflect.Slice {
|
|
|
+ return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
|
|
|
+ }
|
|
|
+
|
|
|
+ taskFormList = make([]interface{}, 0)
|
|
|
+ taskFormList = taskForm.([]interface{})
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上线时间
|
|
|
+ var createTimeList []interface{}
|
|
|
+ if createTime != nil {
|
|
|
+ if reflect.TypeOf(createTime).Kind() != reflect.Slice {
|
|
|
+ return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
|
|
|
+ }
|
|
|
+ createTimeList = make([]interface{}, 0)
|
|
|
+ createTimeList = createTime.([]interface{})
|
|
|
+ }
|
|
|
|
|
|
- platformList = make([]interface{}, 0)
|
|
|
- platformList = platform.([]interface{})
|
|
|
- }*/
|
|
|
+ // 如果有商品类目的过滤条件,则将过滤条件保存于categoryFormList
|
|
|
+ var categoryFormList []interface{}
|
|
|
+ if categoryForm != nil {
|
|
|
+ if reflect.TypeOf(categoryForm).Kind() != reflect.Slice {
|
|
|
+ return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
|
|
|
+ }
|
|
|
+
|
|
|
+ categoryFormList = make([]interface{}, 0)
|
|
|
+ categoryFormList = categoryForm.([]interface{})
|
|
|
+ }
|
|
|
|
|
|
// 构造查询的条件
|
|
|
startId := pageIndex * cntPerPage
|
|
|
- whereStr := fmt.Sprintf("(selection_status >= %d) AND (status = 0) ", selectionStatusInProgress)
|
|
|
- /* if platformList != nil {
|
|
|
- whereStr = whereStr + " and platform in ("
|
|
|
- for _, v := range platformList {
|
|
|
+ whereStr := fmt.Sprintf("(selection_status >= %d) AND (status = 0)", selectionStatusInProgress)
|
|
|
+ if taskFormList != nil {
|
|
|
+ whereStr += " and task_mode in ("
|
|
|
+ for _, v := range taskFormList {
|
|
|
+ whereStr += v.(string) + ", "
|
|
|
+ }
|
|
|
+
|
|
|
+ whereStr = whereStr[0 : len(whereStr)-2]
|
|
|
+ whereStr += ")"
|
|
|
+ }
|
|
|
+ if secFormList != nil {
|
|
|
+ whereStr += " and sample_mode in ("
|
|
|
+ for _, v := range secFormList {
|
|
|
+ whereStr += v.(string) + ", "
|
|
|
+ }
|
|
|
+
|
|
|
+ whereStr = whereStr[0 : len(whereStr)-2]
|
|
|
+ whereStr += ")"
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理 selectionFormList (创建时间的过滤条件)
|
|
|
+ if createTimeList != nil {
|
|
|
+ whereStr += " AND created_at >= (NOW() - INTERVAL "
|
|
|
+ for _, v := range createTimeList {
|
|
|
+ switch v.(string) {
|
|
|
+ case "1": // 近7天
|
|
|
+ whereStr += "7 DAY"
|
|
|
+ case "2": // 近30天
|
|
|
+ whereStr += "30 DAY"
|
|
|
+ case "3": // 近90天
|
|
|
+ whereStr += "90 DAY"
|
|
|
+ default:
|
|
|
+ continue // 无效的过滤条件,跳过
|
|
|
+ }
|
|
|
+ }
|
|
|
+ whereStr += ")"
|
|
|
+ }
|
|
|
+
|
|
|
+ //商品类目 来自product
|
|
|
+ if categoryFormList != nil {
|
|
|
+ whereStr += " and product_category in ("
|
|
|
+ for _, v := range categoryFormList {
|
|
|
whereStr += v.(string) + ", "
|
|
|
}
|
|
|
|
|
|
whereStr = whereStr[0 : len(whereStr)-2]
|
|
|
whereStr += ")"
|
|
|
- }*/
|
|
|
-
|
|
|
- //if taskFormList != nil {
|
|
|
- // whereStr += " and task_mode in ("
|
|
|
- // for _, v := range taskFormList {
|
|
|
- // whereStr += v.(string) + ", "
|
|
|
- // }
|
|
|
- //
|
|
|
- // whereStr = whereStr[0 : len(whereStr)-2]
|
|
|
- // whereStr += ")"
|
|
|
- //}
|
|
|
- //if secFormList != nil {
|
|
|
- // whereStr += " and sample_mode in ("
|
|
|
- // for _, v := range secFormList {
|
|
|
- // whereStr += v.(string) + ", "
|
|
|
- // }
|
|
|
- //
|
|
|
- // whereStr = whereStr[0 : len(whereStr)-2]
|
|
|
- // whereStr += ")"
|
|
|
- //}
|
|
|
- //
|
|
|
- //if categoryFormList != nil {
|
|
|
- // whereStr += " and product_category in ("
|
|
|
- // for _, v := range categoryFormList {
|
|
|
- // whereStr += v.(string) + ", "
|
|
|
- // }
|
|
|
- //
|
|
|
- // whereStr = whereStr[0 : len(whereStr)-2]
|
|
|
- // whereStr += ")"
|
|
|
- //}
|
|
|
-
|
|
|
- ////搜索栏
|
|
|
- //if searchValue != nil {
|
|
|
- // whereStr += " and selection_name like '%" + searchValue.(string) + "%'"
|
|
|
- //}
|
|
|
-
|
|
|
- // 查询所有selection
|
|
|
- //YounggeeSelectionInfo含有表中的所有属性
|
|
|
- var selectionList = []model.YounggeeSelectionInfo{}
|
|
|
- //err := g.Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Scan(&selectionList)
|
|
|
- //展示带货商品的排序规则 预估赚、ddl未处理
|
|
|
- err := g.Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Order("commission_rate DESC , task_reward DESC ").Scan(&selectionList)
|
|
|
- if err != nil {
|
|
|
- return &TalentHttpResult{Code: -3, Msg: "查询数据库失败"}
|
|
|
- }
|
|
|
- //fmt.Println("****searchValue:", searchValue)
|
|
|
- //fmt.Println("****secFormList:", secFormList)
|
|
|
- //fmt.Println("****taskFormList:", taskFormList)
|
|
|
-
|
|
|
- fmt.Println("****whereStr: ", whereStr)
|
|
|
+ }
|
|
|
+
|
|
|
+ //搜索栏
|
|
|
+ if searchValue != nil {
|
|
|
+ whereStr += " and selection_name like '%" + searchValue.(string) + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ fmt.Println("whereStr----->:", whereStr)
|
|
|
|
|
|
// 判断请求页面是否超过最大页面
|
|
|
- c, err := g.DB().Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Count()
|
|
|
+ c, err := g.DB().Model("younggee_selection_info").WithAll().Where(whereStr).Count()
|
|
|
+ fmt.Println("满足条件的selection数目--", c)
|
|
|
if err != nil {
|
|
|
return &TalentHttpResult{Code: -4, Msg: err.Error(), Data: nil}
|
|
|
}
|
|
@@ -174,22 +176,216 @@ func GetSelectionList(r *ghttp.Request) *TalentHttpResult {
|
|
|
if pageIndex+1 > maxPage {
|
|
|
return &TalentHttpResult{Code: -5, Msg: "over max page"}
|
|
|
}
|
|
|
+ fmt.Println("hereiiiii")
|
|
|
|
|
|
var selectionInfoList = youngee_talent_model.SelectionInfoList{
|
|
|
Count: c,
|
|
|
}
|
|
|
|
|
|
- err = g.DB().Model(dao.YounggeeSelectionInfo.Table).WithAll().Where(whereStr).
|
|
|
- Order("selection_status ASC , task_ddl DESC , commission_rate DESC , task_reward DESC, selection_id").Limit(startId, cntPerPage).Scan(&selectionInfoList.SelectionDetail)
|
|
|
+ err = g.DB().Model("younggee_selection_info").WithAll().
|
|
|
+ Where(whereStr).
|
|
|
+ Order("task_ddl DESC").Limit(startId, cntPerPage).Scan(&selectionInfoList.SelectionDetail)
|
|
|
if err != nil {
|
|
|
return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
|
|
|
}
|
|
|
|
|
|
selectionInfoList.MaxPage = maxPage
|
|
|
|
|
|
+ //已经拿到了数据(where之后)。根据product中的字段排序
|
|
|
+ sort.Slice(selectionInfoList.SelectionDetail, func(i, j int) bool {
|
|
|
+ // 获取当前的产品信息
|
|
|
+ productI := selectionInfoList.SelectionDetail[i].YounggeeProduct
|
|
|
+ productJ := selectionInfoList.SelectionDetail[j].YounggeeProduct
|
|
|
+ // 计算 commission_price
|
|
|
+ commissionPriceI := productI.ExclusiveCommission * 0.01 * productI.ProductPrice
|
|
|
+ commissionPriceJ := productJ.ExclusiveCommission * 0.01 * productJ.ProductPrice
|
|
|
+
|
|
|
+ // 根据 sortField 选择排序的字段
|
|
|
+ switch sortField {
|
|
|
+ case "sales_count":
|
|
|
+ if orderTag == 1 {
|
|
|
+ return productI.SalesCount > productJ.SalesCount // 降序
|
|
|
+ }
|
|
|
+ return productI.SalesCount < productJ.SalesCount // 升序
|
|
|
+
|
|
|
+ case "exclusive_commission":
|
|
|
+ if orderTag == 1 {
|
|
|
+ return productI.ExclusiveCommission > productJ.ExclusiveCommission // 降序
|
|
|
+ }
|
|
|
+ return productI.ExclusiveCommission < productJ.ExclusiveCommission // 升序
|
|
|
+
|
|
|
+ case "commission_price":
|
|
|
+ if orderTag == 1 {
|
|
|
+ return commissionPriceI > commissionPriceJ // 降序
|
|
|
+ }
|
|
|
+ return commissionPriceI < commissionPriceJ // 升序
|
|
|
+
|
|
|
+ case "product_price":
|
|
|
+ if orderTag == 1 {
|
|
|
+ return productI.ProductPrice > productJ.ProductPrice // 降序
|
|
|
+ }
|
|
|
+ return productI.ProductPrice < productJ.ProductPrice // 升序
|
|
|
+
|
|
|
+ default:
|
|
|
+ // 如果没有匹配的字段,则不做排序,默认排序
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
return &TalentHttpResult{Code: 0, Msg: "success", Data: selectionInfoList}
|
|
|
}
|
|
|
|
|
|
+// 获取项目信息列表service
|
|
|
+//func GetSelectionList(r *ghttp.Request) *TalentHttpResult {
|
|
|
+//
|
|
|
+// pageIndex := r.GetQueryInt("idx", -1)
|
|
|
+// cntPerPage := r.GetQueryInt("cnt", -1)
|
|
|
+// //platform := r.Get("platform")
|
|
|
+// //secForm := r.Get("secform")
|
|
|
+// //taskForm := r.Get("taskform")
|
|
|
+// //categoryForm := r.Get("categoryform")
|
|
|
+// //searchValue := r.Get("searchvalue")
|
|
|
+// //if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
|
|
|
+// // return &TalentHttpResult{Code: -1, Msg: "参数错误"}
|
|
|
+// //}
|
|
|
+// //
|
|
|
+// //// 如果有领样形式的过滤条件,则将过滤条件保存于secFormList
|
|
|
+// //var secFormList []interface{}
|
|
|
+// //if secForm != nil {
|
|
|
+// // if reflect.TypeOf(secForm).Kind() != reflect.Slice {
|
|
|
+// // return &TalentHttpResult{Code: -2, Msg: "搜索条件领样形式错误"}
|
|
|
+// // }
|
|
|
+// //
|
|
|
+// // secFormList = make([]interface{}, 0)
|
|
|
+// // secFormList = secForm.([]interface{})
|
|
|
+// //}
|
|
|
+// //
|
|
|
+// //// 如果有任务形式的过滤条件,则将过滤条件保存于taskFormList
|
|
|
+// //var taskFormList []interface{}
|
|
|
+// //if taskForm != nil {
|
|
|
+// // if reflect.TypeOf(taskForm).Kind() != reflect.Slice {
|
|
|
+// // return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
|
|
|
+// // }
|
|
|
+// //
|
|
|
+// // taskFormList = make([]interface{}, 0)
|
|
|
+// // taskFormList = taskForm.([]interface{})
|
|
|
+// //}
|
|
|
+// //
|
|
|
+// //// 如果有商品类目的过滤条件,则将过滤条件保存于categoryFormList
|
|
|
+// //var categoryFormList []interface{}
|
|
|
+// //if categoryForm != nil {
|
|
|
+// // if reflect.TypeOf(categoryForm).Kind() != reflect.Slice {
|
|
|
+// // return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
|
|
|
+// // }
|
|
|
+// //
|
|
|
+// // categoryFormList = make([]interface{}, 0)
|
|
|
+// // categoryFormList = categoryForm.([]interface{})
|
|
|
+// //}
|
|
|
+//
|
|
|
+// // 如果有平台的过滤条件,则将平台列表保存于platformList 弃用
|
|
|
+// /* var platformList []interface{}
|
|
|
+// if platform != nil {
|
|
|
+// if reflect.TypeOf(platform).Kind() != reflect.Slice {
|
|
|
+// return &TalentHttpResult{Code: -2, Msg: "搜索条件平台类型错误"}
|
|
|
+// }
|
|
|
+//
|
|
|
+// platformList = make([]interface{}, 0)
|
|
|
+// platformList = platform.([]interface{})
|
|
|
+// }*/
|
|
|
+//
|
|
|
+// // 构造查询的条件
|
|
|
+// startId := pageIndex * cntPerPage
|
|
|
+// whereStr := fmt.Sprintf("(selection_status >= %d) AND (status = 0) ", selectionStatusInProgress)
|
|
|
+// /* if platformList != nil {
|
|
|
+// whereStr = whereStr + " and platform in ("
|
|
|
+// for _, v := range platformList {
|
|
|
+// whereStr += v.(string) + ", "
|
|
|
+// }
|
|
|
+//
|
|
|
+// whereStr = whereStr[0 : len(whereStr)-2]
|
|
|
+// whereStr += ")"
|
|
|
+// }*/
|
|
|
+//
|
|
|
+// //if taskFormList != nil {
|
|
|
+// // whereStr += " and task_mode in ("
|
|
|
+// // for _, v := range taskFormList {
|
|
|
+// // whereStr += v.(string) + ", "
|
|
|
+// // }
|
|
|
+// //
|
|
|
+// // whereStr = whereStr[0 : len(whereStr)-2]
|
|
|
+// // whereStr += ")"
|
|
|
+// //}
|
|
|
+// //if secFormList != nil {
|
|
|
+// // whereStr += " and sample_mode in ("
|
|
|
+// // for _, v := range secFormList {
|
|
|
+// // whereStr += v.(string) + ", "
|
|
|
+// // }
|
|
|
+// //
|
|
|
+// // whereStr = whereStr[0 : len(whereStr)-2]
|
|
|
+// // whereStr += ")"
|
|
|
+// //}
|
|
|
+// //
|
|
|
+// //if categoryFormList != nil {
|
|
|
+// // whereStr += " and product_category in ("
|
|
|
+// // for _, v := range categoryFormList {
|
|
|
+// // whereStr += v.(string) + ", "
|
|
|
+// // }
|
|
|
+// //
|
|
|
+// // whereStr = whereStr[0 : len(whereStr)-2]
|
|
|
+// // whereStr += ")"
|
|
|
+// //}
|
|
|
+//
|
|
|
+// ////搜索栏
|
|
|
+// //if searchValue != nil {
|
|
|
+// // whereStr += " and selection_name like '%" + searchValue.(string) + "%'"
|
|
|
+// //}
|
|
|
+//
|
|
|
+// // 查询所有selection
|
|
|
+// //YounggeeSelectionInfo含有表中的所有属性
|
|
|
+// var selectionList = []model.YounggeeSelectionInfo{}
|
|
|
+// //err := g.Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Scan(&selectionList)
|
|
|
+// //展示带货商品的排序规则 预估赚、ddl未处理
|
|
|
+// err := g.Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Order("commission_rate DESC , task_reward DESC ").Scan(&selectionList)
|
|
|
+// if err != nil {
|
|
|
+// return &TalentHttpResult{Code: -3, Msg: "查询数据库失败"}
|
|
|
+// }
|
|
|
+// //fmt.Println("****searchValue:", searchValue)
|
|
|
+// //fmt.Println("****secFormList:", secFormList)
|
|
|
+// //fmt.Println("****taskFormList:", taskFormList)
|
|
|
+//
|
|
|
+// fmt.Println("****whereStr: ", whereStr)
|
|
|
+//
|
|
|
+// // 判断请求页面是否超过最大页面
|
|
|
+// c, err := g.DB().Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Count()
|
|
|
+// if err != nil {
|
|
|
+// return &TalentHttpResult{Code: -4, Msg: err.Error(), Data: nil}
|
|
|
+// }
|
|
|
+//
|
|
|
+// maxPage := c / cntPerPage
|
|
|
+// if c%cntPerPage > 0 {
|
|
|
+// maxPage += 1
|
|
|
+// }
|
|
|
+//
|
|
|
+// if pageIndex+1 > maxPage {
|
|
|
+// return &TalentHttpResult{Code: -5, Msg: "over max page"}
|
|
|
+// }
|
|
|
+//
|
|
|
+// var selectionInfoList = youngee_talent_model.SelectionInfoList{
|
|
|
+// Count: c,
|
|
|
+// }
|
|
|
+//
|
|
|
+// err = g.DB().Model(dao.YounggeeSelectionInfo.Table).WithAll().Where(whereStr).
|
|
|
+// //Order("selection_status ASC , task_ddl DESC , commission_rate DESC , task_reward DESC, selection_id").Limit(startId, cntPerPage).Scan(&selectionInfoList.SelectionDetail)
|
|
|
+// Order("commission_rate DESC").Limit(startId, cntPerPage).Scan(&selectionInfoList.SelectionDetail)
|
|
|
+// if err != nil {
|
|
|
+// return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
|
|
|
+// }
|
|
|
+//
|
|
|
+// selectionInfoList.MaxPage = maxPage
|
|
|
+//
|
|
|
+// return &TalentHttpResult{Code: 0, Msg: "success", Data: selectionInfoList}
|
|
|
+//}
|
|
|
+
|
|
|
// 获取带货收藏列表
|
|
|
func GetSelectionCollectionList(r *ghttp.Request) *TalentHttpResult {
|
|
|
// 从 session 中获取 talent_id
|
|
@@ -307,11 +503,24 @@ func GetSelectionDetail(r *ghttp.Request) *TalentHttpResult {
|
|
|
|
|
|
var selectionDetail *youngee_talent_model.SelectionDetail
|
|
|
err = g.DB().Model(youngee_talent_model.SelectionDetail{}).WithAll().Where("selection_id", sid).Scan(&selectionDetail)
|
|
|
+ //填充收藏信息
|
|
|
+ collectionInfo := []youngee_talent_model.SelectionCollection{}
|
|
|
+ err = g.DB().Model("younggee_selection_collect_info").Where("selection_id=? and talent_id = ?", sid, tid).Scan(&collectionInfo)
|
|
|
+ if err != nil {
|
|
|
+ return &TalentHttpResult{Code: -1, Msg: err.Error()}
|
|
|
+ }
|
|
|
+ //已被收藏
|
|
|
+ if len(collectionInfo) != 0 && collectionInfo[0].Deleted == 0 { //有数据 且 没取消收藏
|
|
|
+ selectionDetail.IsCollected = 1
|
|
|
+ } else {
|
|
|
+ selectionDetail.IsCollected = 0 //没数据 或 有数据但取消了收藏
|
|
|
+ }
|
|
|
+ //返回的data作为收藏接口的is_collect字段传入
|
|
|
if err != nil {
|
|
|
return &TalentHttpResult{Code: -3, Msg: err.Error()}
|
|
|
}
|
|
|
// 查询younggee_product表数据
|
|
|
- var younggeeProduct []*youngee_talent_model.YounggeeProduct
|
|
|
+ var younggeeProduct *youngee_talent_model.YounggeeProduct
|
|
|
err = g.DB().Model(youngee_talent_model.YounggeeProduct{}).WithAll().Where("product_id", pid).Scan(&younggeeProduct)
|
|
|
if err != nil {
|
|
|
return &TalentHttpResult{Code: -3, Msg: err.Error()}
|
|
@@ -545,17 +754,28 @@ func SignUpSecTaskWithKsAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
return &TalentHttpResult{Code: -17, Msg: "younggee_sec_task_info delete failed"}
|
|
|
}
|
|
|
err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
- // 减少选品库存
|
|
|
- whereCondition1 := g.Map{
|
|
|
- dao.YounggeeSelectionInfo.Columns.SelectionId: selectionDetail.SelectionId,
|
|
|
- }
|
|
|
+ //// 减少选品库存
|
|
|
+ //whereCondition1 := g.Map{
|
|
|
+ // dao.YounggeeSelectionInfo.Columns.SelectionId: selectionDetail.SelectionId,
|
|
|
+ //}
|
|
|
+ //updateData := g.Map{
|
|
|
+ // dao.YounggeeSelectionInfo.Columns.RemainNum: gdb.Raw(fmt.Sprintf("%s - 1", dao.YounggeeSelectionInfo.Columns.RemainNum)),
|
|
|
+ //
|
|
|
+ //}
|
|
|
+ //_, err = tx.Ctx(ctx).Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition1).Data(updateData).Update()
|
|
|
+ //if err != nil {
|
|
|
+ // return err
|
|
|
+ //}
|
|
|
updateData := g.Map{
|
|
|
- dao.YounggeeSelectionInfo.Columns.RemainNum: gdb.Raw(fmt.Sprintf("%s - 1", dao.YounggeeSelectionInfo.Columns.RemainNum)),
|
|
|
+ "remain_num": selectionDetail.RemainNum - 1,
|
|
|
+ "enroll_num": selectionDetail.EnrollNum + 1,
|
|
|
}
|
|
|
- _, err = tx.Ctx(ctx).Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition1).Data(updateData).Update()
|
|
|
+
|
|
|
+ _, err = tx.Ctx(ctx).Model("younggee_selection_info").Where("selection_id=?", selectionDetail.SelectionId).Data(updateData).Update()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
// 新建任务,初始化状态为待发货
|
|
|
secTaskInfo.TaskStage = 6
|
|
|
_, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo).Insert()
|
|
@@ -674,7 +894,7 @@ func SignUpSecTaskFromWindow(r *ghttp.Request) *TalentHttpResult {
|
|
|
return &TalentHttpResult{Code: -16, Msg: err.Error(), Data: nil}
|
|
|
}
|
|
|
//2.如果task不为空。取出free_stage的值。插入的值含有删除数据的free_stage
|
|
|
- //这种情况出现在报名只有又点击加入橱窗
|
|
|
+ //这种情况出现在报名之后又点击加入橱窗
|
|
|
if len(secTaskInfoList) != 0 {
|
|
|
free_stage := secTaskInfoList[0].FreeStage
|
|
|
//删除旧的,
|