package order import ( "app.yhyue.com/moapp/jybase/common" "context" "fmt" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/util/gconv" "jyOrderManager/internal/jyutil" "jyOrderManager/internal/model" "k8s.io/apimachinery/pkg/util/json" "log" "strconv" "strings" ) // StatusRights 身份 1 部门经理2 销管 3 温月 func StatusRights(id int) int { //获取查询审核订单权益功能 var equity int examine := g.Cfg().MustGet(context.Background(), "examine").Maps() for _, m := range examine { for _, s := range gconv.Ints(m["userid"]) { if s == id { equity = gconv.Int(m["equity"]) } } } return equity } func ExamineList(ctx context.Context, param model.OrderExamineListParams) (map[string]interface{}, error) { var ( condition = []string{ "is_backstage_order=1", } innerSale = "" adminId = gconv.Int(jyutil.GetUserMsgFromCtx(ctx).EntUserId) ) equity := StatusRights(adminId) if param.SaleDep != "" { var queryArr []string for _, v := range strings.Split(param.SaleDep, ",") { deptId := gconv.Int(strings.TrimSpace(v)) if deptId != 0 { if name := jyutil.JyDepartmentManager.GetFullDeptName(deptId); name != "" { queryArr = append(queryArr, name) } } } if len(queryArr) > 0 { innerSale += fmt.Sprintf(" and s.saler_dept in ('%s') ", strings.Join(queryArr, "','")) } } else { if equity == 1 { depIds := jyutil.DepId(adminId) log.Println("depIds", depIds) ids := []string{} for _, v := range depIds { ids = append(ids, strconv.Itoa(v)) } if len(ids) > 0 { condition = append(condition, fmt.Sprintf("s.saler_dept_id in (%s)", strings.Join(ids, ","))) } } } if param.AuditStatus == "-1" { condition = append(condition, `(audit_status in (-2,-3,-4,1,2,4) or (audit_status=3 and locate('"audit_type":"人工审核"', filter)>0))`) } else if param.AuditStatus == "4" { condition = append(condition, "audit_status in (-2,-3,-4)") } else if param.AuditStatus == "" { condition = append(condition, "audit_status in (1,2,4)") } else if param.AuditStatus == "3" { condition = append(condition, "audit_status =3") //condition = append(condition, `locate('"audit_type":"人工审核"', filter)>0`) } else if param.AuditStatus == "5" { condition = append(condition, "audit_status =4") //condition = append(condition, `locate('"audit_type":"人工审核"', filter)>0`) } else { condition = append(condition, fmt.Sprintf("audit_status =%s", param.AuditStatus)) } if param.OrderCode != "" { condition = append(condition, fmt.Sprintf("order_code like '%%%s%%'", param.OrderCode)) } if param.SalePerson != "" { innerSale += fmt.Sprintf(" and s.saler_name like '%%%s%%' ", param.SalePerson) //condition = append(condition, "salesperson like '%"+param.SalePerson+"%'") } data := map[string]interface{}{ "lists": []map[string]interface{}{}, "total": 0, } qCount := fmt.Sprintf("SELECT * FROM(select DISTINCT(d.order_code) from dataexport_order d inner join order_sale_record s on ( d.order_code=s.ordercode and (s.state=1 or s.state=2) %s) where %s )as orderData", innerSale, strings.Join(condition, " and ")) log.Println("count sql", qCount) count, _ := g.DB().GetCount(ctx, qCount) if count > 0 { q := fmt.Sprintf("select GROUP_CONCAT(s.saler_dept SEPARATOR ',') as saleDep,order_code,GROUP_CONCAT(s.saler_name SEPARATOR ',') as salesperson,audit_status,d.id,(SELECT filter FROM jy_order_detail where order_code = d.order_code order by final_price desc,id desc LIMIT 1) as product_type,(SELECT product_type FROM jy_order_detail where order_code = d.order_code order by final_price desc,id desc LIMIT 1) as filter, order_code as a ,\n (case WHEN last_update_time IS NULL THEN d.create_time else last_update_time end ) as create_time from dataexport_order d inner join order_sale_record s on ( d.order_code=s.ordercode and (s.state=1 or s.state=2) %s) where %s group by d.order_code order by create_time limit %d ,%d", innerSale, strings.Join(condition, " and "), param.Offset, param.PageSize) log.Println("订单审核列表sql:", q) res, _ := g.DB().Query(ctx, q) if !res.IsEmpty() { showDeptMap := map[string]string{} saleCodeD, _ := g.DB().Query(ctx, "SELECT `code`,`show` FROM dict_dep") if !saleCodeD.IsEmpty() { for _, vv := range saleCodeD.List() { showDeptMap[common.ObjToString(vv["code"])] = common.ObjToString(vv["show"]) } for _, vv := range res.List() { productType := common.ObjToString(vv["product_type"]) if productType == "大会员-AI中标预测包" || productType == "大会员-招标文件解读" { vv["product_type"] = "大会员-补充包" } filterMap := make(map[string]interface{}) if err := json.Unmarshal([]byte(common.ObjToString(vv["filter"])), &filterMap); err == nil && len(filterMap) > 0 { if filterMap["xcx_account_id"] != nil && filterMap["fromMiniCode"] != nil { vv["orderProducttype"] = "碎片化小程序" } } //2:一审通过 -2 一审退回 4 二审通过 -3 二审退回 -4 三审退回 3:审核通过 auditStatus := common.IntAll(vv["audit_status"]) auditButtShow := 0 /*if auditStatus == 2 || auditStatus == 4 || auditStatus == 3 { auditButtShow = 0 }*/ switch equity { //2:一审通过 -2 一审退回 4 二审通过 -3 二审退回 -4 三审退回 3:审核通过 case 1: //部门经理 if auditStatus == 1 { auditButtShow = 1 } case 2: //销管 if auditStatus == 2 { auditButtShow = 1 } case 5: // if auditStatus == 4 { auditButtShow = 1 } } vv["auditButtShow"] = auditButtShow } } } data["lists"] = res.List() data["total"] = count } return data, nil }