diff --git a/controllers/client/good.go b/controllers/client/good.go index ae90485..6aee0be 100644 --- a/controllers/client/good.go +++ b/controllers/client/good.go @@ -109,7 +109,7 @@ func (t *GoodCtl) ListOrder() { for index, order := range orders { order.ServicePhone = option.MainServicePhone for _, sub := range subs { - if fmt.Sprint(order.Id) == sub["order_id"] { + if order.Id == sub.OrderId { orders[index].SubOrders = append(orders[index].SubOrders, sub) } } diff --git a/controllers/client/order_entry.go b/controllers/client/order_entry.go index 9a57f58..852615c 100644 --- a/controllers/client/order_entry.go +++ b/controllers/client/order_entry.go @@ -521,7 +521,7 @@ func (t *OrderEntryCtl) EntryOrders() { for i := range list { s := make([]interface{}, 0) for _, sub := range subs { - if sub["order_id"] == fmt.Sprint(list[i].OrderId) { + if sub.OrderId == list[i].OrderId { s = append(s, sub) } } diff --git a/controllers/pc/order_draw.go b/controllers/pc/order_draw.go index a3d9ada..400fce4 100644 --- a/controllers/pc/order_draw.go +++ b/controllers/pc/order_draw.go @@ -492,14 +492,14 @@ type OrdersResult struct { // 获取所有订单 type SpecialOrdersResult struct { - Id int `json:"id"` - UserId int `json:"user_id"` - AreaName string `json:"area_name"` - EntryPersonName string `json:"entry_person_name"` - Username string `json:"username"` - Phone string `json:"phone"` - Address string `json:"address"` - Goods []map[string]string `json:"goods"` + Id int `json:"id"` + UserId int `json:"user_id"` + AreaName string `json:"area_name"` + EntryPersonName string `json:"entry_person_name"` + Username string `json:"username"` + Phone string `json:"phone"` + Address string `json:"address"` + Goods []*models.SubOrderResult `json:"goods"` } func (t *OrderDrawCtl) Orders() { @@ -534,7 +534,7 @@ func (t *OrderDrawCtl) Orders() { t.CheckErr(err) for i := range orders { for j := range subs { - if fmt.Sprint(orders[i].Id) == subs[j]["order_id"] { + if orders[i].Id == subs[j].OrderId { orders[i].Goods = append(orders[i].Goods, subs[j]) } } diff --git a/models/customer_goods.go b/models/customer_goods.go index eb55bae..49b6966 100644 --- a/models/customer_goods.go +++ b/models/customer_goods.go @@ -14,15 +14,15 @@ type CustomerGoods struct { CreatedAt time.Time `json:"created_at" xorm:"created comment('创建时间') TIMESTAMP"` UpdatedAt time.Time `json:"updated_at" xorm:"updated comment('更新时间') TIMESTAMP"` - ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"` - AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"` - GoodsPicUrl interface{} `json:"goods_pic_url" xorm:"json comment('商品图片')"` - IsForceAdded int `json:"is_force_added" xorm:"not null default 0 comment('是否强制上架0不强制1强制') TINYINT(1)"` - FixedField string `json:"fixed_field" xorm:"not null default '' comment('固定不可改字段,|分隔') VARCHAR(255)"` - Stock int `json:"stock" xorm:"not null default 0 comment('库存-1的时候无上限') INT(18)"` - Name string `json:"name" xorm:"not null default '' comment('商品名称') VARCHAR(255)"` - Price float64 `json:"price" xorm:"not null default 0.00 comment('商品单价') DECIMAL(18,2)"` - Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"` + ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"` + AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"` + GoodsPicUrl []interface{} `json:"goods_pic_url" xorm:"json comment('商品图片')"` + IsForceAdded int `json:"is_force_added" xorm:"not null default 0 comment('是否强制上架0不强制1强制') TINYINT(1)"` + FixedField string `json:"fixed_field" xorm:"not null default '' comment('固定不可改字段,|分隔') VARCHAR(255)"` + Stock int `json:"stock" xorm:"not null default 0 comment('库存-1的时候无上限') INT(18)"` + Name string `json:"name" xorm:"not null default '' comment('商品名称') VARCHAR(255)"` + Price float64 `json:"price" xorm:"not null default 0.00 comment('商品单价') DECIMAL(18,2)"` + Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"` //// 无关变量 GoodType int `json:"good_type" xorm:"-"` diff --git a/models/customer_order.go b/models/customer_order.go index 30cf96c..420af3e 100644 --- a/models/customer_order.go +++ b/models/customer_order.go @@ -48,11 +48,11 @@ type CustomerOrder struct { GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"` // 无关变量 - OrderTime string `json:"order_time,omitempty" xorm:"-"` - Good *CustomerGoods `json:"good,omitempty" xorm:"-"` - User *User `json:"user,omitempty" xorm:"-"` - ServicePhone string `json:"service_phone" xorm:"-"` - SubOrders []map[string]string `json:"sub_orders,omitempty" xorm:"-"` + OrderTime string `json:"order_time,omitempty" xorm:"-"` + Good *CustomerGoods `json:"good,omitempty" xorm:"-"` + User *User `json:"user,omitempty" xorm:"-"` + ServicePhone string `json:"service_phone" xorm:"-"` + SubOrders []*SubOrderResult `json:"sub_orders,omitempty" xorm:"-"` } func (t *CustomerOrder) TableName() string { diff --git a/models/customer_order_sub.go b/models/customer_order_sub.go index 187de9c..3da30b9 100644 --- a/models/customer_order_sub.go +++ b/models/customer_order_sub.go @@ -22,7 +22,7 @@ type CustomerOrderSub struct { GoodPrice float64 `json:"good_price" xorm:"not null default 0.00 comment('商品价格') DECIMAL(18,2)"` // 无关变量 - GoodsPicUrl string `json:"goods_pic_url" xorm:"extends"` + GoodsPicUrl interface{} `json:"goods_pic_url" xorm:"extends"` } func (t *CustomerOrderSub) TableName() string { @@ -33,7 +33,16 @@ func (t *CustomerOrderSub) Alias(n string) string { return fmt.Sprintf("%s as %s", t.TableName(), n) } -func GetCustomerOrderSubsByOrderIds(orderIds interface{}) (subs []map[string]string, err error) { +type SubOrderResult struct { + OrderId int `json:"order_id"` + GoodsId int `json:"goods_id"` + GoodsNum int `json:"goods_num"` + GoodName string `json:"good_name"` + GoodPrice float64 `json:"good_price"` + GoodsPicUrl []interface{} `json:"goods_pic_url"` +} + +func GetCustomerOrderSubsByOrderIds(orderIds interface{}) (subs []*SubOrderResult, err error) { err = core.GetXormAuto().Table(new(CustomerOrderSub)).Alias("s"). Select("s.order_id, s.goods_id, s.goods_num, s.good_name, s.good_price, g.goods_pic_url"). Join("left", new(CustomerGoods).Alias("g"), "g.id=s.goods_id").