package dal import ( "fmt" "gopkg.in/guregu/null.v3" "xiaoniaokuaiyan.com/xiaoniao/entity" "xiaoniaokuaiyan.com/xiaoniao/util" ) type OrderResult struct { Id string `db:"id"` //订单编号 Name string `db:"name"` //客户姓名 Gender int `db:"gender"` //姓名 Age int `db:"age"` //年龄 Birthday string `db:"birthday"` Address string `db:"address"` //上门地址 DetailAddress string `db:"detail_address"` //详细地址 VisitDate null.String `db:"visit_date"` //上门日期 VisitTimeRange null.String `db:"visit_time_range"` //上门时间段 Status int `db:"status"` //订单状态(1待支付,2待接单-匹配客户经理以及护士,3待上门,4待上传化验结果,5已完成) WorkFee null.Int `db:"work_fee"` //上门费 FreeFee int `db:"free_fee"` //优惠费用 RepeatItemFee int `db:"repeat_item_fee"` //重复项减免费用 Payment int `db:"payment,omitempty"` //订单需支付金额 ActualPayment null.Int `db:"actual_payment"` //实际支付金额 PaymentTime null.String `db:"payment_time,omitempty"` //支付时间 PayType null.Int `db:"pay_type,omitempty"` //支付类型 PayNo null.String `db:"pay_no"` //支付流水号 CustomMobile string `db:"custom_mobile"` //下单人电话 Mobile string `db:"mobile"` //被下单人电话 CreatedAt string `db:"created_at"` //下单时间*/ Products []entity.OrderProduct `db:"-"` DeliverUsers []entity.DeliverUser `db:"-"` IsViewReport string `db:"is_view_report"` ReportPicture string `db:"report_picture"` IsNotice null.String `db:"is_notice"` Express null.String `db:"express"` ExpressNumber null.String `db:"expressnumber"` DelayDeadtime uint `db:"delay_deadtime" json:"delay_deadtime"` //订单失效时间延迟时长 LinkerId int `db:"linker_id"` RelId int `db:"-"` Source string `db:"source"` NeedEmptiness null.Int `db:"need_emptiness"` ReportPeriod null.String `db:"report_period"` PressurePipe null.String `db:"pressure_pipe"` BloodAddress null.String `db:"blood_address"` Notice null.String `db:"notice"` Remark1 null.String `db:"remark1"` Remark null.String `db:"remark"` IdNum null.String `db:"id_num"` EVisitDate null.String `db:"e_visit_date",json:"EVisitDate"` EVisitTimeRange null.String `db:"e_visit_time_range",json:"EVisitTimeRange"` Zone null.String `db:"zone" json:"zone"` VCode null.String `db:"vcode" json:"vcode"` JDOrderID null.String `db:"jd_order_id" json:"jd_order_id"` PreOrderId null.String `db:"pre_order_id" json:"PreOrderId"` //20211112 主单id,订单变为服务单 CompleteTime null.String `db:"complete_time" json:"complete_time"` //20230904 完成时间 ShareSource null.String `db:"share_source" json:"share_source"` } func (oitem *OrderResult) FetchProduct() error { db := util.GetSqlDB() plist := []entity.OrderProduct{} 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 = ?" err := db.Select(&plist, strSql, oitem.Id) if err != nil { return err } oitem.Products = plist oitem.DeliverUsers = []entity.DeliverUser{} // fetch deliveruser 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 = ?" err = db.Select(&oitem.DeliverUsers, strSql, oitem.Id) if err != nil { return err } if len(oitem.DeliverUsers) > 0 { strduids := "" for _, du := range oitem.DeliverUsers { strduids += fmt.Sprintf("%d,", du.Id) } strduids = strduids[0 : len(strduids)-1] strSql = "select delever_uer_id, pic from t_deliver_user_pic where delever_uer_id in(" + strduids + ") and type='qualifiction' and is_delete='N'" var tempPicList = []struct { DuId int `db:"delever_uer_id"` Pic string `db:"pic"` }{} db.Select(&tempPicList, strSql) for i, du := range oitem.DeliverUsers { for _, pic := range tempPicList { if pic.DuId == int(du.Id) { oitem.DeliverUsers[i].Qualifiction = append(oitem.DeliverUsers[i].Qualifiction, pic.Pic) } } } } strSql = "select rel_id from t_custom_linker_rel where id = ?;" var relIds = []int{} db.Select(&relIds, strSql, oitem.LinkerId) if len(relIds) > 0 { oitem.RelId = relIds[0] } return nil } type OrderListResult []*OrderResult func (olr OrderListResult) FetchProduct() error { var ids string = "" length := len(olr) if length <= 0 { return nil } var lids string for i, oitem := range olr { if i < length-1 { ids += "'" + oitem.Id + "'" + "," lids += fmt.Sprintf("'%d',", oitem.LinkerId) } else { ids += "'" + oitem.Id + "'" lids += fmt.Sprintf("'%d'", oitem.LinkerId) } } db := util.GetSqlDB() //strSql := "select order_id, product_id, product_name, price, picture,quantity from t_order_product where order_id in (" + ids + ");" 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 + ");" plist := []entity.OrderProduct{} err := db.Select(&plist, strSql) if err != nil { return err } if len(plist) == 0 { return nil } grpPitems := map[string][]entity.OrderProduct{} for _, pitem := range plist { /*if _, ok := grpPitems[pitem.OrderId]; !ok { grpPitems[pitem.OrderId] = []entity.OrderProduct{} }*/ grpPitems[pitem.OrderId] = append(grpPitems[pitem.OrderId], pitem) } for _, oitem := range olr { oitem.Products = append(oitem.Products, grpPitems[oitem.Id]...) } //attach rel_id strSql = fmt.Sprintf("select id, rel_id from t_custom_linker where id in (%s)", lids) var relIds = []struct { LID int `db:"id"` RelId int `db:"rel_id"` }{} err = db.Select(&relIds, strSql) if err != nil { return err } for _, oitem := range olr { for _, rt := range relIds { if oitem.LinkerId == rt.LID { oitem.RelId = rt.RelId } } } return nil }