123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- 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,
- }
- var listArr []map[string]interface{}
- qCount := fmt.Sprintf("SELECT count(1) 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(DISTINCT s.saler_dept SEPARATOR ',') as saleDep,order_code,GROUP_CONCAT(DISTINCT s.saler_name SEPARATOR ',') as salesperson,audit_status,d.id, 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-1)*param.PageSize, 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() {
- orderDetail, _ := g.DB().GetOne(ctx, fmt.Sprintf("SELECT product_type,filter,service_type FROM jy_order_detail where order_code = '%s' and status =1 order by final_price desc,id desc LIMIT 1", vv["order_code"]))
- if !orderDetail.IsEmpty() {
- vv["product_type"] = orderDetail.Map()["product_type"]
- vv["filter"] = orderDetail.Map()["filter"]
- vv["service_type"] = orderDetail.Map()["service_type"]
- }
- 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
- listArr = append(listArr, vv)
- }
- }
- }
- data["lists"] = listArr
- data["total"] = count
- }
- return data, nil
- }
|