|
@@ -0,0 +1,160 @@
|
|
|
+package order
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "github.com/beego/beego/v2/client/orm"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+type CygxOrderResp struct {
|
|
|
+ OrderId int `orm:"column(order_id);pk";comment:"订单id"`
|
|
|
+ OrderCode string `comment:"订单编号"`
|
|
|
+ OutTradeCode string `comment:"外部交易号"`
|
|
|
+ PaymentType int `comment:"支付类型。取值范围:1微信支付,2支付宝支付。"`
|
|
|
+ GoodsName string `comment:"商品名称"`
|
|
|
+ GoodsId int `comment:"商品ID"`
|
|
|
+ BuyerInvoice string `comment:"买家发票信息"`
|
|
|
+ GoodsMoney float64 `comment:"商品总价"`
|
|
|
+ OrderMoney float64 `comment:"订单总价"`
|
|
|
+ Point int `comment:"订单消耗积分"`
|
|
|
+ PointMoney float64 `comment:"订单消耗积分抵多少钱"`
|
|
|
+ PayMoney float64 `comment:"订单实付金额"`
|
|
|
+ RefundMoney float64 `comment:"订单退款金额"`
|
|
|
+ OrderStatus int `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
|
|
|
+ PayTime time.Time `comment:"订单付款时间"`
|
|
|
+ SourceId int `comment:"来源ID"`
|
|
|
+ Source string `comment:"来源\n报告 :article\n活动 :activity"`
|
|
|
+ SourceTitle string `comment:"来源名称,活动或者报告标题"`
|
|
|
+ UserId int `comment:"用户ID"`
|
|
|
+ Mobile string `comment:"手机号"`
|
|
|
+ Email string `comment:"邮箱"`
|
|
|
+ CompanyId int `comment:"公司ID"`
|
|
|
+ CompanyName string `comment:"公司名称"`
|
|
|
+ RealName string `comment:"用户实际名称"`
|
|
|
+ SellerName string `comment:"所属销售"`
|
|
|
+ CreateTime time.Time `comment:"创建时间"`
|
|
|
+ ModifyTime time.Time `comment:"修改时间"`
|
|
|
+ RegisterPlatform int `comment:"来源 1小程序,2:网页"`
|
|
|
+ StartDate time.Time `comment:"开始时间"`
|
|
|
+ EndDate time.Time `comment:"结束时间"`
|
|
|
+}
|
|
|
+
|
|
|
+// 订单表
|
|
|
+type CygxOrder struct {
|
|
|
+ OrderId int `orm:"column(order_id);pk";comment:"订单id"`
|
|
|
+ OrderCode string `comment:"订单编号"`
|
|
|
+ OutTradeCode string `comment:"外部交易号"`
|
|
|
+ PaymentType int `comment:"支付类型。取值范围:1微信支付,2支付宝支付。"`
|
|
|
+ GoodsName string `comment:"商品名称"`
|
|
|
+ GoodsId int `comment:"商品ID"`
|
|
|
+ BuyerInvoice string `comment:"买家发票信息"`
|
|
|
+ GoodsMoney float64 `comment:"商品总价"`
|
|
|
+ OrderMoney float64 `comment:"订单总价"`
|
|
|
+ Point int `comment:"订单消耗积分"`
|
|
|
+ PointMoney float64 `comment:"订单消耗积分抵多少钱"`
|
|
|
+ PayMoney float64 `comment:"订单实付金额"`
|
|
|
+ RefundTime time.Time `comment:"订单退款时间"`
|
|
|
+ RefundMoney float64 `comment:"订单退款金额"`
|
|
|
+ OrderStatus int `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
|
|
|
+ PayTime time.Time `comment:"订单付款时间"`
|
|
|
+ SourceId int `comment:"来源ID"`
|
|
|
+ Source string `comment:"来源\n报告 :article\n活动 :activity"`
|
|
|
+ SourceTitle string `comment:"来源名称,活动或者报告标题"`
|
|
|
+ UserId int `comment:"用户ID"`
|
|
|
+ Mobile string `comment:"手机号"`
|
|
|
+ Email string `comment:"邮箱"`
|
|
|
+ CompanyId int `comment:"公司ID"`
|
|
|
+ CompanyName string `comment:"公司名称"`
|
|
|
+ RealName string `comment:"用户实际名称"`
|
|
|
+ SellerName string `comment:"所属销售"`
|
|
|
+ SellerId int `comment:"所属销售Id"`
|
|
|
+ CreateTime time.Time `comment:"创建时间"`
|
|
|
+ ModifyTime time.Time `comment:"修改时间"`
|
|
|
+ RegisterPlatform int `comment:"来源 1小程序,2:网页"`
|
|
|
+ OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
|
|
|
+ StartDate time.Time `comment:"开始时间"`
|
|
|
+ EndDate time.Time `comment:"结束时间"`
|
|
|
+}
|
|
|
+
|
|
|
+// 订单操作表
|
|
|
+type CygxOrderAction struct {
|
|
|
+ ActionId int64 `orm:"column(action_id);pk"` // 动作id
|
|
|
+ Action string // 动作内容
|
|
|
+ OrderStatus int // 订单状态,0:已取消、1:待支付、2:已支付、3:已退款
|
|
|
+ OrderStatusText string // 订单状态名称
|
|
|
+ OrderCode string // 订单编号
|
|
|
+ UserId int // 用户ID
|
|
|
+ Mobile string // 手机号
|
|
|
+ Email string // 邮箱
|
|
|
+ CompanyId int // 公司ID
|
|
|
+ CompanyName string // 公司名称
|
|
|
+ RealName string // 用户实际名称
|
|
|
+ SellerName string // 所属销售
|
|
|
+ CreateTime time.Time // 创建时间
|
|
|
+ ModifyTime time.Time // 修改时间
|
|
|
+ RegisterPlatform int // 来源 1小程序,2:网页
|
|
|
+ AdminId int // 管理员ID
|
|
|
+ AdminName string // 管理员姓名
|
|
|
+}
|
|
|
+
|
|
|
+func GetCygxOrderList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxOrder, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := `SELECT *
|
|
|
+ FROM
|
|
|
+ cygx_order
|
|
|
+ WHERE 1 = 1 ` + condition
|
|
|
+ sql += ` LIMIT ?,? `
|
|
|
+ _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 自动取消订单
|
|
|
+func CancelCygxOrder(item *CygxOrder) (err error) {
|
|
|
+ o, err := orm.NewOrm().Begin()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ fmt.Println(err)
|
|
|
+ if err == nil {
|
|
|
+ o.Commit()
|
|
|
+ } else {
|
|
|
+ o.Rollback()
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ itemOrderAction := new(CygxOrderAction)
|
|
|
+ itemOrderAction.Action = "超时自动取消订单"
|
|
|
+ itemOrderAction.OrderStatus = 0
|
|
|
+ itemOrderAction.OrderStatusText = "已取消"
|
|
|
+ itemOrderAction.OrderCode = item.OrderCode
|
|
|
+ itemOrderAction.UserId = item.UserId
|
|
|
+ itemOrderAction.Mobile = item.Mobile
|
|
|
+ itemOrderAction.Email = item.Email
|
|
|
+ itemOrderAction.CompanyId = item.CompanyId
|
|
|
+ itemOrderAction.CompanyName = item.CompanyName
|
|
|
+ itemOrderAction.RealName = item.RealName
|
|
|
+ itemOrderAction.SellerName = item.SellerName
|
|
|
+ itemOrderAction.CreateTime = time.Now()
|
|
|
+ itemOrderAction.ModifyTime = time.Now()
|
|
|
+ itemOrderAction.RegisterPlatform = item.RegisterPlatform
|
|
|
+
|
|
|
+ _, err = o.Insert(itemOrderAction) // 写入订单操作信息
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ updateParams := make(map[string]interface{})
|
|
|
+ updateParams["OrderStatus"] = 0
|
|
|
+ updateParams["ModifyTime"] = item.ModifyTime
|
|
|
+ ptrStructOrTableName := "cygx_order"
|
|
|
+ whereParam := map[string]interface{}{"order_code": item.OrderCode}
|
|
|
+ qs := o.QueryTable(ptrStructOrTableName)
|
|
|
+ for expr, exprV := range whereParam {
|
|
|
+ qs = qs.Filter(expr, exprV)
|
|
|
+ }
|
|
|
+ _, err = qs.Update(updateParams)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|