互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/ouxuanserver/osmanthuswine/src/core"
  6. )
  7. const CustomerOrderSubTN = TableNamePrefix + "customer_order_sub"
  8. type CustomerOrderSub struct {
  9. Id int `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
  10. IsDelete bool `json:"is_delete" xorm:"not null default 0 comment('软删除') TINYINT(1)"`
  11. CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
  12. UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
  13. OrderId int `json:"order_id" xorm:"not null default 0 comment('订单id') VARCHAR(128)"`
  14. GoodsId int `json:"goods_id" xorm:"not null default 0 comment('商品id') INT(11)"`
  15. GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"`
  16. GoodName string `json:"good_name" xorm:"not null default '' comment('商品名字') VARCHAR(128)"`
  17. GoodPrice float64 `json:"good_price" xorm:"not null default 0.00 comment('商品价格') DECIMAL(18,2)"`
  18. // 无关变量
  19. GoodsPicUrl interface{} `json:"goods_pic_url" xorm:"extends"`
  20. }
  21. func (t *CustomerOrderSub) TableName() string {
  22. return CustomerOrderSubTN
  23. }
  24. func (t *CustomerOrderSub) Alias(n string) string {
  25. return fmt.Sprintf("%s as %s", t.TableName(), n)
  26. }
  27. type SubOrderResult struct {
  28. OrderId int `json:"order_id"`
  29. GoodsId int `json:"goods_id"`
  30. GoodsNum int `json:"goods_num"`
  31. GoodName string `json:"good_name"`
  32. GoodPrice float64 `json:"good_price"`
  33. GoodsPicUrl []interface{} `json:"goods_pic_url"`
  34. }
  35. func GetCustomerOrderSubsByOrderIds(orderIds interface{}) (subs []*SubOrderResult, err error) {
  36. err = core.GetXormAuto().Table(new(CustomerOrderSub)).Alias("s").
  37. Select("s.order_id, s.goods_id, s.goods_num, s.good_name, s.good_price, g.goods_pic_url").
  38. Join("left", new(CustomerGoods).Alias("g"), "g.id=s.goods_id").
  39. Where("s.is_delete=0").In("s.order_id", orderIds).Desc("s.created_at").Find(&subs)
  40. return
  41. }
  42. func GetCustomerOrderSubsByOrderId(orderId interface{}) (subs []map[string]string, err error) {
  43. err = core.GetXormAuto().Table(new(CustomerOrderSub)).Alias("s").
  44. Select("s.order_id, s.goods_id, s.goods_num, s.good_name, s.good_price, g.goods_pic_url").
  45. Join("left", new(CustomerGoods).Alias("g"), "g.id=s.goods_id").
  46. Where("s.is_delete=0 and s.order_id", orderId).Desc("s.created_at").Find(&subs)
  47. return
  48. }
  49. func GetSubOrdersByOrderId(orderId interface{}) ([]*CustomerOrderSub, error) {
  50. subs := make([]*CustomerOrderSub, 0)
  51. err := core.GetXormAuto().Where("is_delete=0 and order_id=?", orderId).Find(&subs)
  52. return subs, err
  53. }