result.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package dal
  2. import (
  3. "fmt"
  4. "gopkg.in/guregu/null.v3"
  5. "xiaoniaokuaiyan.com/xiaoniao/entity"
  6. "xiaoniaokuaiyan.com/xiaoniao/util"
  7. )
  8. type OrderResult struct {
  9. Id string `db:"id"` //订单编号
  10. Name string `db:"name"` //客户姓名
  11. Gender int `db:"gender"` //姓名
  12. Age int `db:"age"` //年龄
  13. Birthday string `db:"birthday"`
  14. Address string `db:"address"` //上门地址
  15. DetailAddress string `db:"detail_address"` //详细地址
  16. VisitDate null.String `db:"visit_date"` //上门日期
  17. VisitTimeRange null.String `db:"visit_time_range"` //上门时间段
  18. Status int `db:"status"` //订单状态(1待支付,2待接单-匹配客户经理以及护士,3待上门,4待上传化验结果,5已完成)
  19. WorkFee null.Int `db:"work_fee"` //上门费
  20. FreeFee int `db:"free_fee"` //优惠费用
  21. RepeatItemFee int `db:"repeat_item_fee"` //重复项减免费用
  22. Payment int `db:"payment,omitempty"` //订单需支付金额
  23. ActualPayment null.Int `db:"actual_payment"` //实际支付金额
  24. PaymentTime null.String `db:"payment_time,omitempty"` //支付时间
  25. PayType null.Int `db:"pay_type,omitempty"` //支付类型
  26. PayNo null.String `db:"pay_no"` //支付流水号
  27. CustomMobile string `db:"custom_mobile"` //下单人电话
  28. Mobile string `db:"mobile"` //被下单人电话
  29. CreatedAt string `db:"created_at"` //下单时间*/
  30. Products []entity.OrderProduct `db:"-"`
  31. DeliverUsers []entity.DeliverUser `db:"-"`
  32. IsViewReport string `db:"is_view_report"`
  33. ReportPicture string `db:"report_picture"`
  34. IsNotice null.String `db:"is_notice"`
  35. Express null.String `db:"express"`
  36. ExpressNumber null.String `db:"expressnumber"`
  37. DelayDeadtime uint `db:"delay_deadtime" json:"delay_deadtime"` //订单失效时间延迟时长
  38. LinkerId int `db:"linker_id"`
  39. RelId int `db:"-"`
  40. Source string `db:"source"`
  41. NeedEmptiness null.Int `db:"need_emptiness"`
  42. ReportPeriod null.String `db:"report_period"`
  43. PressurePipe null.String `db:"pressure_pipe"`
  44. BloodAddress null.String `db:"blood_address"`
  45. Notice null.String `db:"notice"`
  46. Remark1 null.String `db:"remark1"`
  47. Remark null.String `db:"remark"`
  48. IdNum null.String `db:"id_num"`
  49. EVisitDate null.String `db:"e_visit_date",json:"EVisitDate"`
  50. EVisitTimeRange null.String `db:"e_visit_time_range",json:"EVisitTimeRange"`
  51. Zone null.String `db:"zone" json:"zone"`
  52. VCode null.String `db:"vcode" json:"vcode"`
  53. JDOrderID null.String `db:"jd_order_id" json:"jd_order_id"`
  54. PreOrderId null.String `db:"pre_order_id" json:"PreOrderId"` //20211112 主单id,订单变为服务单
  55. CompleteTime null.String `db:"complete_time" json:"complete_time"` //20230904 完成时间
  56. ShareSource null.String `db:"share_source" json:"share_source"`
  57. }
  58. func (oitem *OrderResult) FetchProduct() error {
  59. db := util.GetSqlDB()
  60. plist := []entity.OrderProduct{}
  61. strSql := "select order_id, product_id,t2.sale_mode, t1.product_name,cast(t1.price as signed) as price, t1.picture,t1.quantity,t2.discount_switch, t2.is_tip, t2.tip_content, t2.is_jiyin,t2.searchs from t_order_product t1 left join t_product t2 on t1.product_id = t2.id where order_id = ?"
  62. err := db.Select(&plist, strSql, oitem.Id)
  63. if err != nil {
  64. return err
  65. }
  66. oitem.Products = plist
  67. oitem.DeliverUsers = []entity.DeliverUser{}
  68. // fetch deliveruser
  69. strSql = "select t3.id, t3.name, t3.age, t3.gender, t3.head_pic, t3.tel, t3.remark, t2.career,t3.qualifiction from t_order t1 inner join t_order_deliver_user t2 on t1.id = t2.order_id inner join t_deliver_user t3 on t2.deliver_user_id = t3.id where t1.id = ?"
  70. err = db.Select(&oitem.DeliverUsers, strSql, oitem.Id)
  71. if err != nil {
  72. return err
  73. }
  74. if len(oitem.DeliverUsers) > 0 {
  75. strduids := ""
  76. for _, du := range oitem.DeliverUsers {
  77. strduids += fmt.Sprintf("%d,", du.Id)
  78. }
  79. strduids = strduids[0 : len(strduids)-1]
  80. strSql = "select delever_uer_id, pic from t_deliver_user_pic where delever_uer_id in(" + strduids + ") and type='qualifiction' and is_delete='N'"
  81. var tempPicList = []struct {
  82. DuId int `db:"delever_uer_id"`
  83. Pic string `db:"pic"`
  84. }{}
  85. db.Select(&tempPicList, strSql)
  86. for i, du := range oitem.DeliverUsers {
  87. for _, pic := range tempPicList {
  88. if pic.DuId == int(du.Id) {
  89. oitem.DeliverUsers[i].Qualifiction = append(oitem.DeliverUsers[i].Qualifiction, pic.Pic)
  90. }
  91. }
  92. }
  93. }
  94. strSql = "select rel_id from t_custom_linker_rel where id = ?;"
  95. var relIds = []int{}
  96. db.Select(&relIds, strSql, oitem.LinkerId)
  97. if len(relIds) > 0 {
  98. oitem.RelId = relIds[0]
  99. }
  100. return nil
  101. }
  102. type OrderListResult []*OrderResult
  103. func (olr OrderListResult) FetchProduct() error {
  104. var ids string = ""
  105. length := len(olr)
  106. if length <= 0 {
  107. return nil
  108. }
  109. var lids string
  110. for i, oitem := range olr {
  111. if i < length-1 {
  112. ids += "'" + oitem.Id + "'" + ","
  113. lids += fmt.Sprintf("'%d',", oitem.LinkerId)
  114. } else {
  115. ids += "'" + oitem.Id + "'"
  116. lids += fmt.Sprintf("'%d'", oitem.LinkerId)
  117. }
  118. }
  119. db := util.GetSqlDB()
  120. //strSql := "select order_id, product_id, product_name, price, picture,quantity from t_order_product where order_id in (" + ids + ");"
  121. strSql := "select order_id, product_id, product_name, t1.price, t1.picture,quantity,t2.sale_mode from t_order_product t1 left join t_product t2 on t1.product_id = t2.id where order_id in (" + ids + ");"
  122. plist := []entity.OrderProduct{}
  123. err := db.Select(&plist, strSql)
  124. if err != nil {
  125. return err
  126. }
  127. if len(plist) == 0 {
  128. return nil
  129. }
  130. grpPitems := map[string][]entity.OrderProduct{}
  131. for _, pitem := range plist {
  132. /*if _, ok := grpPitems[pitem.OrderId]; !ok {
  133. grpPitems[pitem.OrderId] = []entity.OrderProduct{}
  134. }*/
  135. grpPitems[pitem.OrderId] = append(grpPitems[pitem.OrderId], pitem)
  136. }
  137. for _, oitem := range olr {
  138. oitem.Products = append(oitem.Products, grpPitems[oitem.Id]...)
  139. }
  140. //attach rel_id
  141. strSql = fmt.Sprintf("select id, rel_id from t_custom_linker where id in (%s)", lids)
  142. var relIds = []struct {
  143. LID int `db:"id"`
  144. RelId int `db:"rel_id"`
  145. }{}
  146. err = db.Select(&relIds, strSql)
  147. if err != nil {
  148. return err
  149. }
  150. for _, oitem := range olr {
  151. for _, rt := range relIds {
  152. if oitem.LinkerId == rt.LID {
  153. oitem.RelId = rt.RelId
  154. }
  155. }
  156. }
  157. return nil
  158. }