examineList.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package order
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "fmt"
  6. "github.com/gogf/gf/v2/frame/g"
  7. "github.com/gogf/gf/v2/util/gconv"
  8. "jyOrderManager/internal/jyutil"
  9. "jyOrderManager/internal/model"
  10. "k8s.io/apimachinery/pkg/util/json"
  11. "log"
  12. "strconv"
  13. "strings"
  14. )
  15. // StatusRights 身份 1 部门经理2 销管 3 温月
  16. func StatusRights(id int) int {
  17. //获取查询审核订单权益功能
  18. var equity int
  19. examine := g.Cfg().MustGet(context.Background(), "examine").Maps()
  20. for _, m := range examine {
  21. for _, s := range gconv.Ints(m["userid"]) {
  22. if s == id {
  23. equity = gconv.Int(m["equity"])
  24. }
  25. }
  26. }
  27. return equity
  28. }
  29. func ExamineList(ctx context.Context, param model.OrderExamineListParams) (map[string]interface{}, error) {
  30. var (
  31. condition = []string{
  32. "is_backstage_order=1",
  33. }
  34. innerSale = ""
  35. adminId = gconv.Int(jyutil.GetUserMsgFromCtx(ctx).EntUserId)
  36. )
  37. equity := StatusRights(adminId)
  38. if param.SaleDep != "" {
  39. var queryArr []string
  40. for _, v := range strings.Split(param.SaleDep, ",") {
  41. deptId := gconv.Int(strings.TrimSpace(v))
  42. if deptId != 0 {
  43. if name := jyutil.JyDepartmentManager.GetFullDeptName(deptId); name != "" {
  44. queryArr = append(queryArr, name)
  45. }
  46. }
  47. }
  48. if len(queryArr) > 0 {
  49. innerSale += fmt.Sprintf(" and s.saler_dept in ('%s') ", strings.Join(queryArr, "','"))
  50. }
  51. } else {
  52. if equity == 1 {
  53. depIds := jyutil.DepId(adminId)
  54. log.Println("depIds", depIds)
  55. ids := []string{}
  56. for _, v := range depIds {
  57. ids = append(ids, strconv.Itoa(v))
  58. }
  59. if len(ids) > 0 {
  60. condition = append(condition, fmt.Sprintf("s.saler_dept_id in (%s)", strings.Join(ids, ",")))
  61. }
  62. }
  63. }
  64. if param.AuditStatus == "-1" {
  65. condition = append(condition, `(audit_status in (-2,-3,-4,1,2,4) or (audit_status=3 and locate('"audit_type":"人工审核"', filter)>0))`)
  66. } else if param.AuditStatus == "4" {
  67. condition = append(condition, "audit_status in (-2,-3,-4)")
  68. } else if param.AuditStatus == "" {
  69. condition = append(condition, "audit_status in (1,2,4)")
  70. } else if param.AuditStatus == "3" {
  71. condition = append(condition, "audit_status =3")
  72. //condition = append(condition, `locate('"audit_type":"人工审核"', filter)>0`)
  73. } else if param.AuditStatus == "5" {
  74. condition = append(condition, "audit_status =4")
  75. //condition = append(condition, `locate('"audit_type":"人工审核"', filter)>0`)
  76. } else {
  77. condition = append(condition, fmt.Sprintf("audit_status =%s", param.AuditStatus))
  78. }
  79. if param.OrderCode != "" {
  80. condition = append(condition, fmt.Sprintf("order_code like '%%%s%%'", param.OrderCode))
  81. }
  82. if param.SalePerson != "" {
  83. innerSale += fmt.Sprintf(" and s.saler_name like '%%%s%%' ", param.SalePerson)
  84. //condition = append(condition, "salesperson like '%"+param.SalePerson+"%'")
  85. }
  86. data := map[string]interface{}{
  87. "lists": []map[string]interface{}{},
  88. "total": 0,
  89. }
  90. 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 "))
  91. log.Println("count sql", qCount)
  92. count, _ := g.DB().GetCount(ctx, qCount)
  93. if count > 0 {
  94. 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)
  95. log.Println("订单审核列表sql:", q)
  96. res, _ := g.DB().Query(ctx, q)
  97. if !res.IsEmpty() {
  98. showDeptMap := map[string]string{}
  99. saleCodeD, _ := g.DB().Query(ctx, "SELECT `code`,`show` FROM dict_dep")
  100. if !saleCodeD.IsEmpty() {
  101. for _, vv := range saleCodeD.List() {
  102. showDeptMap[common.ObjToString(vv["code"])] = common.ObjToString(vv["show"])
  103. }
  104. for _, vv := range res.List() {
  105. productType := common.ObjToString(vv["product_type"])
  106. if productType == "大会员-AI中标预测包" || productType == "大会员-招标文件解读" {
  107. vv["product_type"] = "大会员-补充包"
  108. }
  109. filterMap := make(map[string]interface{})
  110. if err := json.Unmarshal([]byte(common.ObjToString(vv["filter"])), &filterMap); err == nil && len(filterMap) > 0 {
  111. if filterMap["xcx_account_id"] != nil && filterMap["fromMiniCode"] != nil {
  112. vv["orderProducttype"] = "碎片化小程序"
  113. }
  114. }
  115. //2:一审通过 -2 一审退回 4 二审通过 -3 二审退回 -4 三审退回 3:审核通过
  116. auditStatus := common.IntAll(vv["audit_status"])
  117. auditButtShow := 0
  118. /*if auditStatus == 2 || auditStatus == 4 || auditStatus == 3 {
  119. auditButtShow = 0
  120. }*/
  121. switch equity { //2:一审通过 -2 一审退回 4 二审通过 -3 二审退回 -4 三审退回 3:审核通过
  122. case 1: //部门经理
  123. if auditStatus == 1 {
  124. auditButtShow = 1
  125. }
  126. case 2: //销管
  127. if auditStatus == 2 {
  128. auditButtShow = 1
  129. }
  130. case 5: //
  131. if auditStatus == 4 {
  132. auditButtShow = 1
  133. }
  134. }
  135. vv["auditButtShow"] = auditButtShow
  136. }
  137. }
  138. }
  139. data["lists"] = res.List()
  140. data["total"] = count
  141. }
  142. return data, nil
  143. }