examineList.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. var listArr []map[string]interface{}
  91. 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 "))
  92. log.Println("count sql", qCount)
  93. count, _ := g.DB().GetCount(ctx, qCount)
  94. if count > 0 {
  95. 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)
  96. log.Println("订单审核列表sql:", q)
  97. res, _ := g.DB().Query(ctx, q)
  98. if !res.IsEmpty() {
  99. showDeptMap := map[string]string{}
  100. saleCodeD, _ := g.DB().Query(ctx, "SELECT `code`,`show` FROM dict_dep")
  101. if !saleCodeD.IsEmpty() {
  102. for _, vv := range saleCodeD.List() {
  103. showDeptMap[common.ObjToString(vv["code"])] = common.ObjToString(vv["show"])
  104. }
  105. for _, vv := range res.List() {
  106. 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"]))
  107. if !orderDetail.IsEmpty() {
  108. vv["product_type"] = orderDetail.Map()["product_type"]
  109. vv["filter"] = orderDetail.Map()["filter"]
  110. vv["service_type"] = orderDetail.Map()["service_type"]
  111. }
  112. productType := common.ObjToString(vv["product_type"])
  113. if productType == "大会员-AI中标预测包" || productType == "大会员-招标文件解读" {
  114. vv["product_type"] = "大会员-补充包"
  115. }
  116. filterMap := make(map[string]interface{})
  117. if err := json.Unmarshal([]byte(common.ObjToString(vv["filter"])), &filterMap); err == nil && len(filterMap) > 0 {
  118. if filterMap["xcx_account_id"] != nil && filterMap["fromMiniCode"] != nil {
  119. vv["orderProducttype"] = "碎片化小程序"
  120. }
  121. }
  122. //2:一审通过 -2 一审退回 4 二审通过 -3 二审退回 -4 三审退回 3:审核通过
  123. auditStatus := common.IntAll(vv["audit_status"])
  124. auditButtShow := 0
  125. /*if auditStatus == 2 || auditStatus == 4 || auditStatus == 3 {
  126. auditButtShow = 0
  127. }*/
  128. switch equity { //2:一审通过 -2 一审退回 4 二审通过 -3 二审退回 -4 三审退回 3:审核通过
  129. case 1: //部门经理
  130. if auditStatus == 1 {
  131. auditButtShow = 1
  132. }
  133. case 2: //销管
  134. if auditStatus == 2 {
  135. auditButtShow = 1
  136. }
  137. case 5: //
  138. if auditStatus == 4 {
  139. auditButtShow = 1
  140. }
  141. }
  142. vv["auditButtShow"] = auditButtShow
  143. listArr = append(listArr, vv)
  144. }
  145. }
  146. }
  147. data["lists"] = listArr
  148. data["total"] = count
  149. }
  150. return data, nil
  151. }