detail.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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/logic/user"
  10. "jyOrderManager/internal/model"
  11. "log"
  12. "strings"
  13. "time"
  14. )
  15. var (
  16. StampedInterest, SaleChangePower, SaleChangeReason []string
  17. )
  18. func init() {
  19. StampedInterest = g.Cfg().MustGet(context.Background(), "stampedInterest").Strings()
  20. SaleChangePower = g.Cfg().MustGet(context.Background(), "saleChangePower").Strings()
  21. SaleChangeReason = g.Cfg().MustGet(context.Background(), "saleChangeReason").Strings()
  22. }
  23. func Detail(ctx context.Context, param model.OrderDetailParams) (map[string]interface{}, error) {
  24. result := make(map[string]interface{})
  25. //订单 暂无备注字段
  26. orderData, err := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT d.*,d.pay_money+(select IFNULL(sum(payMoney),0) as return_money from moneyCorrection where orderCode='%s') as pay_money,(select a.item_name AS order_parent_name from dict_item a where a.item_code=d.order_channel ) AS order_channel_new FROM dataexport_order d WHERE order_code ='%s' `, param.OrderCode, param.OrderCode))
  27. if err != nil || orderData.IsEmpty() {
  28. return nil, err
  29. }
  30. orderMap := orderData.Map()
  31. payWay := gconv.String(orderData.Map()["pay_way"])
  32. switch {
  33. case strings.Contains(payWay, "wx"):
  34. orderMap["pay_way"] = "微信"
  35. case strings.Contains(payWay, "ali"):
  36. orderMap["pay_way"] = "支付宝"
  37. case strings.Contains(payWay, "trial"):
  38. orderMap["pay_way"] = "其他"
  39. case strings.Contains(payWay, "transferAccounts"):
  40. orderMap["pay_way"] = "对公转账"
  41. case strings.Contains(payWay, "测试使用"):
  42. orderMap["pay_way"] = "测试使用"
  43. }
  44. orderMap["pure_amount"] = common.If(gconv.Int(orderMap["pay_money"])-gconv.Int(orderMap["commission"]) > 0, gconv.Int(orderMap["pay_money"])-gconv.Int(orderMap["commission"]), 0)
  45. //产品
  46. productData, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT * FROM jy_order_detail WHERE order_code =%s `, param.OrderCode))
  47. var productArr []map[string]interface{}
  48. if err != nil || productData.IsEmpty() {
  49. return nil, err
  50. }
  51. for _, m := range productData.List() {
  52. if activityCode := gconv.String(m["activity_code"]); activityCode != "" {
  53. activityData, err := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT * FROM jy_product_activity WHERE code ='%s' `, activityCode))
  54. if err == nil && !activityData.IsEmpty() {
  55. m["activityName"] = gconv.String(activityData.Map()["name"])
  56. }
  57. }
  58. productItem, _ := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT jpi.name,jpc.auto,jpc.code FROM jy_product_item jpi
  59. INNER JOIN jy_product_class jpc on jpi.product_class_id = jpc.id WHERE jpi.code = '%s'`, gconv.String(m["product_code"])))
  60. if !productItem.IsEmpty() {
  61. m["productName"] = productItem.Map()["name"]
  62. m["productItemCode"] = productItem.Map()["code"]
  63. m["auto"] = productItem.Map()["auto"]
  64. } else {
  65. m["productName"] = productItem.Map()["product_type"]
  66. }
  67. if gconv.String(m["product_type"]) == "大会员" && gconv.Int(gconv.Map(m["filter"])["comboId"]) == 0 {
  68. supMap := make(map[string]bool)
  69. for _, s := range gconv.Strings(gconv.Map(m["filter"])["supServiceIds"]) {
  70. supMap[s] = true
  71. }
  72. var ids []string
  73. serviceIds := gconv.Strings(gconv.Map(m["filter"])["serviceIds"])
  74. for _, id := range serviceIds {
  75. ids = append(serviceIds, gconv.String(id))
  76. }
  77. bigService, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT id,s_name FROM bigmember_service WHERE id in (%s) order by id`, strings.Join(ids, ",")))
  78. if !bigService.IsEmpty() {
  79. var (
  80. bigServiceNames []string
  81. supBigServiceNames []string
  82. )
  83. for _, m1 := range bigService.List() {
  84. switch gconv.Int(m1["id"]) {
  85. case 1:
  86. m1["s_name"] = "基础服务"
  87. case 30051, 30052, 30053: //0分报告过滤
  88. continue
  89. }
  90. if supMap[gconv.String(m1["id"])] {
  91. supBigServiceNames = append(supBigServiceNames, gconv.String(m1["s_name"]))
  92. } else {
  93. bigServiceNames = append(bigServiceNames, gconv.String(m1["s_name"]))
  94. }
  95. }
  96. if len(supBigServiceNames) > 0 {
  97. m["bigServiceNames"] = fmt.Sprintf("[补充权益]: %s ;[原已购权益]:%s", strings.Join(supBigServiceNames, "、"), strings.Join(bigServiceNames, "、"))
  98. } else {
  99. m["bigServiceNames"] = strings.Join(bigServiceNames, "、")
  100. }
  101. }
  102. }
  103. if linkedDetailId := gconv.String(m["linked_detail_id"]); linkedDetailId != "" && linkedDetailId != "0" {
  104. var orderArr []map[string]interface{}
  105. //关联订单
  106. if gconv.String(m["product_type"]) != "大会员" && gconv.String(m["product_type"]) != "VIP订阅" {
  107. if linkedOrder := user.SpecialService(ctx, common.InterfaceToStr(orderData.Map()["user_id"]), gconv.String(m["product_type"])); linkedOrder != nil {
  108. m["linkedOrder"] = linkedOrder[0]
  109. }
  110. } else {
  111. switch gconv.Int(orderData.Map()["buy_subject"]) {
  112. case 1:
  113. userData, _ := jyutil.MG.DB().FindOne("user", map[string]interface{}{
  114. "$or": []map[string]interface{}{
  115. {"s_phone": orderData.Map()["user_phone"]},
  116. {"s_m_phone": orderData.Map()["user_phone"]},
  117. },
  118. })
  119. orderProduct, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT b.id,b.service_type,b.order_code,c.create_time FROM jy_order_detail a
  120. INNER JOIN dataexport_order b on a.order_code = b.order_code
  121. WHERE a.status = 1 and a.is_service_open = 1 and b.user_id = '%s' and a.product_type like '%s' ORDER BY b.create_time desc `, gconv.String(m["user_id"]), common.If(gconv.String(m["product_type"]) == "VIP订阅", "%VIP订阅%", "%大会员%")))
  122. if !orderData.IsEmpty() {
  123. for _, m2 := range orderProduct.List() {
  124. orderArr = append(orderArr, map[string]interface{}{
  125. "order_code": m2["order_code"],
  126. "create_time": m2["create_time"],
  127. "service_type": m2["service_type"],
  128. "order_detail_id": m2["id"],
  129. })
  130. }
  131. }
  132. if userData != nil && len(*userData) > 0 {
  133. var (
  134. areaCount, paySubNum int
  135. endTime string
  136. )
  137. switch gconv.String(m["product_type"]) {
  138. case "VIP订阅":
  139. vipInfo := common.ObjToMap((*userData)["o_vipjy"])
  140. buySet := common.ObjToMap((*vipInfo)["o_buyset"])
  141. areaCount = common.IntAll((*buySet)["areacount"])
  142. //判断是新版超级订阅还是老版超级订阅
  143. if common.IntAll((*buySet)["upgrade"]) == 1 {
  144. //newVip = true
  145. }
  146. endTime = time.Unix(common.Int64All((*userData)["l_vip_endtime"]), 0).Format("2006-01-02 15:04:05")
  147. case "大会员":
  148. bigStart := common.Int64All((*userData)["i_member_starttime"])
  149. bigEnd := common.Int64All((*userData)["i_member_endtime"])
  150. memberStatus := common.IntAll((*userData)["i_member_status"])
  151. if memberJyMap, ok1 := ((*userData)["o_member_jy"]).(map[string]interface{}); ok1 {
  152. areaCount = common.IntAll(memberJyMap["i_areacount"])
  153. }
  154. if bigStart >= time.Now().Unix() {
  155. endTime = time.Unix(bigEnd, 0).Format("2006-01-02 15:04:05")
  156. } else if (time.Now().Unix() < bigEnd && memberStatus > 0) || bigStart >= time.Now().Unix() {
  157. endTime = time.Unix(bigEnd, 0).Format("2006-01-02 15:04:05")
  158. }
  159. paySubNum = common.IntAll((*userData)["i_pay_sub_num"]) + common.IntAll((*userData)["i_free_sub_num"]) + 1
  160. }
  161. m["linkedOrder"] = map[string]interface{}{
  162. "name": gconv.String(m["product_type"]), //产品名称
  163. "serviceEndTime": endTime, //服务结束时间
  164. "empowerCount": paySubNum, //服务授权数
  165. "provinceCount": areaCount, //订阅省份
  166. "buySubject": 1, //个体
  167. "orderArr": orderArr, //关联订单
  168. }
  169. }
  170. case 2:
  171. entService, _ := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT a.id,a.product_type,a.end_time,a.start_time,a.empower_count,a.province_count FROM entniche_wait_empower a
  172. INNER JOIN entniche_order b on a.id = b.wait_empower_id
  173. WHERE b.order_detail_id=%s`, linkedDetailId))
  174. if !entService.IsEmpty() {
  175. entOrderService, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT jod.*,do.create_time
  176. FROM jy_order_detail jod
  177. INNER JOIN entniche_order eo ON jod.id = eo.order_detail_id
  178. INNER JOIN dataexport_order do on jod.order_code= do.order_code
  179. WHERE eo.wait_empower_id = %s and jod.is_service_open =1 ORDER BY do.create_time desc`, gconv.String(entService.Map()["id"])))
  180. if !entOrderService.IsEmpty() {
  181. for _, m2 := range entOrderService.List() {
  182. orderArr = append(orderArr, map[string]interface{}{
  183. "order_code": m2["order_code"],
  184. "create_time": m2["create_time"],
  185. "service_type": m2["service_type"],
  186. "order_detail_id": m2["id"],
  187. })
  188. }
  189. m["linkedOrder"] = map[string]interface{}{
  190. "name": gconv.String(entService.Map()["product_type"]), //产品名称
  191. "serviceEndTime": gconv.String(entService.Map()["end_time"]), //服务结束时间
  192. "serviceStartTime": gconv.String(entService.Map()["start_time"]), //服务开始时间
  193. "empowerCount": gconv.String(entService.Map()["empower_count"]), //服务授权数
  194. "provinceCount": gconv.String(entService.Map()["province_count"]), //订阅省份
  195. "buySubject": 2, //个体
  196. "orderArr": orderArr, //关联订单
  197. }
  198. }
  199. }
  200. }
  201. }
  202. switch gconv.String(m["product_type"]) {
  203. case "大会员":
  204. BigFilterFmt(m)
  205. case "VIP订阅":
  206. VipFilterFmt(m)
  207. }
  208. }
  209. productArr = append(productArr, m)
  210. }
  211. result["productData"] = productArr
  212. //对公转账审核记录
  213. orderTransfer, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT * FROM jy_order_transfer WHERE order_code = '%s' order by create_time desc `, param.OrderCode))
  214. if !orderTransfer.IsEmpty() {
  215. result["orderTransfer"] = orderTransfer.List()
  216. }
  217. var (
  218. //佣金 手续费 合同金额 企业
  219. isCommission, isProceduresMoney, isCash, isEnt bool
  220. newEntName string
  221. moneyCorrectionArr []map[string]interface{}
  222. )
  223. //红冲
  224. redPunch := make(map[string]interface{})
  225. subject := orderData.Map()["return_commpany"]
  226. moneyCorrectionData, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT * FROM moneyCorrection WHERE orderCode =%s `, param.OrderCode))
  227. if !moneyCorrectionData.IsEmpty() {
  228. for _, m := range moneyCorrectionData.List() {
  229. if common.InterfaceToStr(m["redType"]) == "金额红冲" {
  230. if common.IntAll(m["payMoney"]) != 0 {
  231. isCash = true
  232. }
  233. if common.IntAll(m["commission"]) != 0 {
  234. isCommission = true
  235. }
  236. if common.IntAll(m["proceduresMoney"]) != 0 {
  237. isProceduresMoney = true
  238. }
  239. if common.InterfaceToStr(m["signingSubject"]) == "" {
  240. m["signingSubject"] = subject
  241. }
  242. } else if strings.Contains(common.InterfaceToStr(m["redType"]), "主体") {
  243. isEnt = true
  244. if common.InterfaceToStr(m["newSigningSubject"]) != "" {
  245. m["signingSubject"] = m["newSigningSubject"]
  246. }
  247. if newSigningSubject := common.InterfaceToStr(m["newSigningSubject"]); newSigningSubject != "" && newEntName == "" {
  248. newEntName = newSigningSubject
  249. }
  250. }
  251. moneyCorrectionArr = append(moneyCorrectionArr, m)
  252. }
  253. if newEntName != "" {
  254. orderMap["return_commpany"] = newEntName
  255. }
  256. }
  257. result["orderData"] = orderMap
  258. redPunch["moneyCorrectionData"] = moneyCorrectionArr
  259. redPunch["isUpCash"] = isCash
  260. redPunch["isUpCommission"] = isCommission
  261. redPunch["isUpProceduresMoney"] = isProceduresMoney
  262. redPunch["isUpEnt"] = isEnt
  263. result["redPunchData"] = redPunch
  264. //合同
  265. contractData, _ := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT * FROM contract WHERE order_code =%s `, param.OrderCode))
  266. if !contractData.IsEmpty() {
  267. contractMap := contractData.Map()
  268. // 合同信息
  269. if contractMap["contract_file_url"] != nil && len(contractMap["contract_file_url"].(string)) > 0 {
  270. index_ := strings.LastIndex(contractMap["contract_file_url"].(string), "/")
  271. if index_ != -1 {
  272. contractMap["contract_file_name"] = contractMap["contract_file_url"].(string)[index_+1:]
  273. }
  274. }
  275. result["contractRes"] = contractMap
  276. }
  277. // 回款信息
  278. var (
  279. returnMoney, plantMoney int
  280. returnArr []map[string]interface{}
  281. )
  282. returnInfo, _ := g.DB().Query(ctx, fmt.Sprintf("SELECT * from return_money_record WHERE order_code=%s and state=1", param.OrderCode))
  283. // 回款交易详情列表
  284. if !returnInfo.IsEmpty() {
  285. for _, d := range returnInfo.List() {
  286. returnMoney += gconv.Int(d["return_money"])
  287. if d["return_voucher_url"] != nil && len(d["return_voucher_url"].(string)) > 0 {
  288. index_ := strings.LastIndex(d["return_voucher_url"].(string), "/")
  289. if index_ != -1 {
  290. d["return_voucher_name"] = d["return_voucher_url"].(string)[index_+1:]
  291. }
  292. }
  293. returnArr = append(returnArr, d)
  294. }
  295. }
  296. result["returnRes"] = map[string]interface{}{
  297. "returnMoney": returnMoney,
  298. "remainingMoney": gconv.Int(orderData.Map()["pay_money"]) - returnMoney,
  299. "returnInfo": returnArr,
  300. }
  301. //回款计划
  302. returnMoneyPlant, err := g.DB().GetOne(ctx, "SELECT * from return_money_plant where order_code = ? order by create_time desc", param.OrderCode)
  303. if !returnMoneyPlant.IsEmpty() {
  304. for _, m2 := range gconv.Maps(returnMoneyPlant.Map()["plantList"]) {
  305. if gconv.String(m2["code"]) == "合计" {
  306. plantMoney = gconv.Int(m2["money"])
  307. }
  308. }
  309. }
  310. result["returnMoneyPlant"] = map[string]interface{}{
  311. "list": returnMoneyPlant.Map(),
  312. "returnMoney": returnMoney,
  313. "plantMoney": plantMoney,
  314. }
  315. //退款
  316. var refundMoney int
  317. refundData, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT rr.*,jpi.name FROM refund_record rr
  318. LEFT JOIN jy_order_detail jod on rr.refund_detail_id = jod.id
  319. LEFT JOIN jy_product_item jpi on jod.product_code = jpi.code
  320. WHERE rr.order_code =%s`, param.OrderCode))
  321. if !refundData.IsEmpty() {
  322. for _, datum := range refundData.List() {
  323. refundMoney += gconv.Int(datum["refund_money"])
  324. }
  325. }
  326. result["refundRes"] = map[string]interface{}{
  327. "refundMoney": refundMoney,
  328. "remainingMoney": gconv.Int(orderData.Map()["pay_money"]) - refundMoney,
  329. "refundInfo": refundData.List(),
  330. }
  331. //审核轨迹详情
  332. recordsData, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT * FROM audit_records WHERE order_code =%s and audit_type = 2 order by create_time desc `, param.OrderCode))
  333. if !recordsData.IsEmpty() {
  334. result["audit"] = recordsData.List()
  335. }
  336. //盖章记录
  337. sealData, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT id,stamp_time,create_time,salesman_id,applicant_id FROM order_seal WHERE order_code = '%s' and status = 0 order by create_time desc `, param.OrderCode))
  338. if !sealData.IsEmpty() {
  339. for _, m := range sealData.List() {
  340. var salesmanName, applicantName string
  341. if salesmanId := gconv.String(m["salesman_id"]); salesmanId != "" {
  342. salesman, _ := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT GROUP_CONCAT(name SEPARATOR ',') as name FROM entniche_user WHERE id IN (%s)`, salesmanId))
  343. if !salesman.IsEmpty() {
  344. salesmanName = gconv.String(salesman.Map()["name"])
  345. }
  346. }
  347. if applicantId := gconv.String(m["applicant_id"]); applicantId != "" {
  348. applicant, _ := g.DB().GetOne(ctx, fmt.Sprintf(`SELECT GROUP_CONCAT(username SEPARATOR ',') as name FROM entniche_user WHERE id IN (%s)`, applicantId))
  349. if !applicant.IsEmpty() {
  350. applicantName = gconv.String(applicant.Map()["name"])
  351. }
  352. }
  353. m["salesperson_name"] = salesmanName
  354. m["applicant_name"] = applicantName
  355. }
  356. result["sealArr"] = sealData.List()
  357. }
  358. //配置盖章权益人
  359. result["stampedInterest"] = StampedInterest
  360. var saleData = map[string]interface{}{
  361. "saleEdit": SaleChangePower, //销售业绩变更展示
  362. }
  363. saleRes, _ := g.DB().Query(ctx, fmt.Sprintf("SELECT d.*,(select CONCAT_WS('/', a.parent_name, a.item_name) AS order_parent_name from dict_item a where a.item_code=d.distribution_channel ) AS order_channel_new FROM order_sale_record d WHERE d.ordercode='%s' and d.state in (1,-1,2) order by d.create_time asc", param.OrderCode))
  364. if !saleRes.IsEmpty() {
  365. var (
  366. //最终业绩
  367. finalArr []map[string]interface{}
  368. finalShowTime string
  369. //记录
  370. record, recordTmp []map[string]interface{}
  371. repeatMapping = map[string]bool{}
  372. zeroChannel = map[string]bool{}
  373. //
  374. )
  375. for _, m := range saleRes.List() {
  376. var (
  377. status = gconv.Int64(m["state"])
  378. money = gconv.Int64(m["money"])
  379. salerId = gconv.Int64(m["saler_Id"])
  380. )
  381. if (status == 1 || status == 2) && money >= 0 { //最终合算
  382. if finalShowTime == "" {
  383. finalShowTime = gconv.String(m["statistics_time"])
  384. }
  385. finalArr = append(finalArr, map[string]interface{}{
  386. "id": salerId,
  387. "name": m["saler_name"],
  388. "saler_dept": m["saler_dept"],
  389. "distribution_channel": m["distribution_channel"],
  390. "order_channel_new": m["order_channel_new"],
  391. "money": money,
  392. })
  393. }
  394. if status == 2 {
  395. continue
  396. }
  397. if gconv.Int(m["change_value"]) == 0 || gconv.Int(m["money"]) == 0 {
  398. zeroChannelKey := fmt.Sprintf("%d_%s", salerId, gconv.String(m["distribution_channel"]))
  399. if zeroChannel[zeroChannelKey] {
  400. continue
  401. }
  402. zeroChannel[zeroChannelKey] = true
  403. }
  404. key := fmt.Sprintf("%d_%s", salerId, gconv.String(m["statistics_time"]))
  405. if repeatMapping[key] {
  406. continue
  407. }
  408. repeatMapping[key] = true
  409. recordTmp = append(recordTmp, map[string]interface{}{
  410. "saler_dept": m["saler_dept"],
  411. "name": m["saler_name"],
  412. "change_value": m["change_value"],
  413. "statistics_time": m["statistics_time"],
  414. "createtime": m["create_time"],
  415. "operator": m["operator"],
  416. "change_reason": m["change_reason"],
  417. "distribution_channel": m["distribution_channel"],
  418. "order_channel_new": m["order_channel_new"],
  419. "money": money,
  420. })
  421. }
  422. for i := len(recordTmp) - 1; i >= 0; i-- {
  423. record = append(record, recordTmp[i])
  424. }
  425. saleData["saleFinal"] = map[string]interface{}{
  426. "list": finalArr,
  427. "time": finalShowTime,
  428. }
  429. saleData["reason"] = SaleChangeReason
  430. saleData["saleRecord"] = record
  431. result["saleDataRes"] = saleData
  432. }
  433. //发票信息
  434. var invoiceMoney int
  435. invoiceRes, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT *,(
  436. SELECT count(1) as count FROM invoice b WHERE b.order_code = a.order_code and b.only_Identifying is not null and b.only_Identifying = a.only_Identifying
  437. ) as isChanged FROM invoice a WHERE order_code = '%s' and invoice_status != -2 and invoice_variety is not null and invoice_variety is not null and invoice_variety not LIKE '%s' ORDER BY create_time DESC`, param.OrderCode, "%纸质%"))
  438. if !invoiceRes.IsEmpty() {
  439. for _, datum := range invoiceRes.List() {
  440. invoiceMoney += gconv.Int(datum["invoice_money"])
  441. }
  442. }
  443. result["invoiceData"] = map[string]interface{}{
  444. "invoiceMoney": invoiceMoney,
  445. "remainingMoney": gconv.Int(orderData.Map()["pay_money"]) - invoiceMoney,
  446. "invoiceInfo": invoiceRes.List(),
  447. }
  448. return result, nil
  449. }
  450. func BigFilterFmt(m map[string]interface{}) {
  451. var bigFilter model.JyBigProductFilter
  452. err := gconv.Struct(m["filter"], bigFilter)
  453. if err != nil {
  454. log.Println("filter err", err)
  455. return
  456. }
  457. productType := "大会员"
  458. switch bigFilter.ComboId {
  459. case 1:
  460. productType += "专家版"
  461. case 2:
  462. productType += "智慧版"
  463. case 3:
  464. productType += "商机版"
  465. case 4:
  466. productType += "试用版"
  467. case 6:
  468. productType += "商机版2.0"
  469. case 7:
  470. productType += "专家版2.0"
  471. default:
  472. //自定义获取每个服务名称
  473. productType += "自定义"
  474. if len(bigFilter.SupServiceIds) == 0 {
  475. m["all_service_name"] = ServiceName(bigFilter.ServiceIds)
  476. }
  477. }
  478. m["product_type"] = productType
  479. if len(bigFilter.SupServiceIds) > 0 { //补充服务 区分升级前 升级后分类
  480. var preUpgradeService []string
  481. //基础服务过滤
  482. for _, id := range bigFilter.ServiceIds {
  483. var isSup bool
  484. for _, serviceId := range bigFilter.SupServiceIds {
  485. if id == serviceId {
  486. isSup = true
  487. break
  488. }
  489. }
  490. if !isSup {
  491. preUpgradeService = append(preUpgradeService, id)
  492. }
  493. }
  494. if bigFilter.ComboId == 0 { //自定义获取下老服务名称 套餐不展示
  495. m["old_service_name"] = ServiceName(preUpgradeService)
  496. }
  497. m["new_service_name"] = ServiceName(bigFilter.SupServiceIds)
  498. }
  499. }
  500. func ServiceName(id []string) (serviceName []string) {
  501. bigService, _ := g.DB().Query(context.Background(), fmt.Sprintf(`SELECT id,s_new_name,i_class,s_count_year FROM bigmember_service WHERE id in (%s) ORDER BY i_class ASC,i_sort ASC`, strings.Join(id, ",")))
  502. if !bigService.IsEmpty() {
  503. for _, m2 := range bigService.List() {
  504. switch m2["i_class"] {
  505. case 1:
  506. serviceName = append(serviceName, "基础服务")
  507. case 2:
  508. serviceName = append(serviceName, fmt.Sprintf("%s%s", m2["s_new_name"],
  509. common.If(gconv.Int(m2["s_count_year"]) > 0, fmt.Sprintf("(%s)个", gconv.String(m2["s_count_year"])), "")))
  510. case 3:
  511. serviceName = append(serviceName, fmt.Sprintf("%s%s", m2["s_new_name"],
  512. common.If(gconv.Int(m2["s_count_year"]) > 0, fmt.Sprintf("(%s)份", gconv.String(m2["s_count_year"])), "")))
  513. case 4:
  514. serviceName = append(serviceName, fmt.Sprintf("%s%s", m2["s_new_name"],
  515. common.If(gconv.Int(m2["s_count_year"]) > 0, fmt.Sprintf(":%s/天", gconv.String(m2["s_count_year"])), "")))
  516. }
  517. }
  518. }
  519. return
  520. }
  521. func VipFilterFmt(m map[string]interface{}) {
  522. //升级订阅增购省份多少个
  523. var vipFilter model.VipCycleFilter
  524. gconv.Struct(m["filter"], vipFilter)
  525. productItem, _ := g.DB().GetOne(context.Background(), fmt.Sprintf(`SELECT * FROM jy_product_item WHERE code = '%s'`, gconv.String(m["product_code"])))
  526. if !productItem.IsEmpty() {
  527. if gconv.Int(productItem.Map()["unit_num"]) < vipFilter.FinalAreaCount {
  528. if vipFilter.FinalAreaCount == -1 || vipFilter.FinalAreaCount > 16 {
  529. m["upgradesNumber"] = 16 - gconv.Int(productItem.Map()["unit_num"])
  530. }
  531. }
  532. }
  533. }