package youngee_task_service import ( "github.com/gogf/gf/util/gconv" "youngmini_server/app/dao" "youngmini_server/app/model" "youngmini_server/app/model/youngee_talent_model" "youngmini_server/app/utils" "github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" ) // 修改达人收货地址 func OnUpdateLogisticsAddress(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Update talent address failed"} } var modifyReq *youngee_talent_model.TaskLogisticsAddress err = r.ParseForm(&modifyReq) if err != nil { return &TalentHttpResult{Code: -2, Msg: "params error"} } address := model.YoungeeTalentDeliveryAddress{ TalentId: tid, RegionCode: modifyReq.RegionCode, DetailAddr: modifyReq.DetailAddr, PhoneNumber: modifyReq.PhoneNumber, ReceiverName: modifyReq.ReceiverName, } // 生成收货地址快照 addrSnap, err := gjson.Encode(address) if err != nil { return &TalentHttpResult{Code: -3, Msg: "encode delivery address snap failed"} } _, err = g.DB().Model(dao.YoungeeTaskInfo.Table).Data("talent_post_addr_snap", addrSnap).Where("task_id = ?", modifyReq.TaskId).Update() if err != nil { return &TalentHttpResult{Code: -4, Msg: "update failed"} } return &TalentHttpResult{Code: 0, Msg: "success"} } // 物流信息汇总 func GetTaskLogisticsNumber(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "获取用户信息失败"} } // 定义物流状态统计结果 type LogisticsStatusCount struct { Pending int `json:"pending"` // 待发货 Shipped int `json:"shipped"` // 已发货 Delivered int `json:"delivered"` // 已签收 } var result LogisticsStatusCount // 定义需要查询的表 tables := []string{"younggee_sec_task_info", "youngee_task_info", "youngee_local_task_info"} // 遍历每个表,查询三种状态的数量 for _, table := range tables { var count int // 查询待发货数量 count, err = g.DB().Model(table). Where("talent_id = ? AND logistics_status = ?", tid, 1). Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "查询待发货数量失败"} } result.Pending += count // 查询已发货数量 count, err = g.DB().Model(table). Where("talent_id = ? AND logistics_status = ?", tid, 2). Count() if err != nil { return &TalentHttpResult{Code: -3, Msg: "查询已发货数量失败"} } result.Shipped += count // 查询已签收数量 count, err = g.DB().Model(table). Where("talent_id = ? AND logistics_status = ?", tid, 3). Count() if err != nil { return &TalentHttpResult{Code: -4, Msg: "查询已签收数量失败"} } result.Delivered += count } // 返回统计结果 return &TalentHttpResult{Code: 0, Msg: "success", Data: result} } // 物流信息汇总 func GetTaskLogisticsList(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "获取用户信息失败"} } tabKey := r.GetQueryInt("tab_key", 0) // 定义表与任务类型的映射 tableTaskTypeMap := map[string]int{ "younggee_sec_task_info": 1, // 带货任务 "youngee_task_info": 2, // 种草任务 "youngee_local_task_info": 3, // 本地生活任务 } // 定义结果集 var taskList []*youngee_talent_model.YoungeeGeneralTaskInfo // 遍历每个表 for table, taskType := range tableTaskTypeMap { //var taskIds []*string // 查询符合条件的 task_id query := g.DB().Model(table).Where("talent_id = ?", tid) switch tabKey { case 1: // 待发货 query = query.Where("logistics_status = ?", 1) case 2: // 已发货 query = query.Where("logistics_status = ?", 2) case 3: // 已签收 query = query.Where("logistics_status = ?", 3) } all, err := query.Fields("task_id").All() array := all.Array() taskIds := gconv.Strings(array) if err != nil { return &TalentHttpResult{Code: -2, Msg: "查询任务ID失败", Data: err.Error()} } // 遍历 task_id 查询详情 for _, taskId := range taskIds { //定义name、photo、price、accountInfo var TaskName string var TaskPhoto string var TaskPrice float64 var AccountInfo *youngee_talent_model.KuaishouUserInfo var SourceType int // 根据任务类型查询对应的任务详情表 switch taskType { case 1: // 带货任务 var taskDetail *youngee_talent_model.SecTaskInfoDetail err = g.DB().Model("younggee_sec_task_info").WithAll().Where("task_id = ?", taskId).Scan(&taskDetail) TaskName = taskDetail.SelectionInfo.SelectionName TaskPhoto = taskDetail.YounggeeProductPhoto[0].PhotoUrl TaskPrice = taskDetail.YounggeeProduct.ProductPrice AccountInfo = taskDetail.KsUserInfo[0] SourceType = 1 //只有公开 case 2: // 种草任务 var taskDetail *youngee_talent_model.YoungeeTaskInfo err = g.DB().Model("youngee_task_info").WithAll().Where("task_id = ?", taskId).Scan(&taskDetail) TaskName = taskDetail.ProjectDetail.ProjectName TaskPhoto = taskDetail.ProjectDetail.YounggeeProductPhoto[0].PhotoUrl TaskPrice = taskDetail.ProjectDetail.YounggeeProduct.ProductPrice AccountInfo = taskDetail.KsUserInfo[0] SourceType = taskDetail.ProjectType case 3: // 本地生活任务 var taskDetail *youngee_talent_model.YoungeeLocalTaskInfo err = g.DB().Model("youngee_local_task_info").WithAll().Where("task_id = ?", taskId).Scan(&taskDetail) TaskName = taskDetail.LocalInfoDetail.LocalName TaskPhoto = taskDetail.LocalInfoDetail.YounggeeProductPhoto[0].PhotoUrl TaskPrice = taskDetail.LocalInfoDetail.YounggeeTeamBuying.TeamBuyingPrice AccountInfo = taskDetail.KsUserInfo[0] SourceType = taskDetail.LocalType } if err != nil { return &TalentHttpResult{Code: -3, Msg: "获取任务详情失败"} } // 组装任务详情 task := &youngee_talent_model.YoungeeGeneralTaskInfo{ TalentId: tid, TaskName: TaskName, // 任务名称 TaskPhoto: TaskPhoto, // 任务图片 TaskPrice: TaskPrice, // 任务价格 AccountInfo: AccountInfo, // 账号信息 SourceType: SourceType, // 1公开,2种草 TaskType: taskType, //1.带货 2.种草 3.本地生活 } taskList = append(taskList, task) } } // 返回结果 return &TalentHttpResult{Code: 0, Msg: "success", Data: taskList} } // 获取物流信息 func GetTaskLogisticsInfo(r *ghttp.Request) *TalentHttpResult { taskId := r.GetQueryInt("task_id", -1) var logistics *model.YoungeeTaskLogistics err := g.Model("youngee_task_logistics").Where("task_id = ?", taskId).Scan(&logistics) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get logistics info failed"} } return &TalentHttpResult{Code: 0, Msg: "success", Data: logistics} }