互动
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

package models
import (
"fmt"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const CustomerOrderSubTN = TableNamePrefix + "customer_order_sub"
type CustomerOrderSub struct {
Id int `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
IsDelete bool `json:"is_delete" xorm:"not null default 0 comment('软删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
OrderId int `json:"order_id" xorm:"not null default 0 comment('订单id') VARCHAR(128)"`
GoodsId int `json:"goods_id" xorm:"not null default 0 comment('商品id') INT(11)"`
GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"`
GoodName string `json:"good_name" xorm:"not null default '' comment('商品名字') VARCHAR(128)"`
GoodPrice float64 `json:"good_price" xorm:"not null default 0.00 comment('商品价格') DECIMAL(18,2)"`
// 无关变量
GoodsPicUrl interface{} `json:"goods_pic_url" xorm:"extends"`
}
func (t *CustomerOrderSub) TableName() string {
return CustomerOrderSubTN
}
func (t *CustomerOrderSub) Alias(n string) string {
return fmt.Sprintf("%s as %s", t.TableName(), n)
}
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").
Where("s.is_delete=0").In("s.order_id", orderIds).Desc("s.created_at").Find(&subs)
return
}
func GetCustomerOrderSubsByOrderId(orderId interface{}) (subs []map[string]string, 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").
Where("s.is_delete=0 and s.order_id", orderId).Desc("s.created_at").Find(&subs)
return
}
func GetSubOrdersByOrderId(orderId interface{}) ([]*CustomerOrderSub, error) {
subs := make([]*CustomerOrderSub, 0)
err := core.GetXormAuto().Where("is_delete=0 and order_id=?", orderId).Find(&subs)
return subs, err
}