|
@@ -1,6 +1,7 @@
|
|
|
package order
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
"time"
|
|
|
)
|
|
@@ -12,12 +13,12 @@ type CygxOrderAddReq struct {
|
|
|
}
|
|
|
|
|
|
type CygxOrder struct {
|
|
|
- OrderID int `orm:"column(order_id);pk";comment:"订单id"`
|
|
|
+ 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"`
|
|
|
+ GoodsId int `comment:"商品ID"`
|
|
|
BuyerInvoice string `comment:"买家发票信息"`
|
|
|
GoodsMoney float64 `comment:"商品总价"`
|
|
|
OrderMoney float64 `comment:"订单总价"`
|
|
@@ -27,13 +28,13 @@ type CygxOrder struct {
|
|
|
RefundMoney float64 `comment:"订单退款金额"`
|
|
|
OrderStatus int `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
|
|
|
PayTime time.Time `comment:"订单付款时间"`
|
|
|
- SourceID int `comment:"来源ID"`
|
|
|
+ SourceId int `comment:"来源ID"`
|
|
|
Source string `comment:"来源\n报告 :article\n活动 :activity"`
|
|
|
SourceTitle string `comment:"来源名称,活动或者报告标题"`
|
|
|
- UserID int `comment:"用户ID"`
|
|
|
+ UserId int `comment:"用户ID"`
|
|
|
Mobile string `comment:"手机号"`
|
|
|
Email string `comment:"邮箱"`
|
|
|
- CompanyID int `comment:"公司ID"`
|
|
|
+ CompanyId int `comment:"公司ID"`
|
|
|
CompanyName string `comment:"公司名称"`
|
|
|
RealName string `comment:"用户实际名称"`
|
|
|
SellerName string `comment:"所属销售"`
|
|
@@ -42,9 +43,65 @@ type CygxOrder struct {
|
|
|
RegisterPlatform int `comment:"来源 1小程序,2:网页"`
|
|
|
}
|
|
|
|
|
|
+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 AddCygxOrder(item *CygxOrder) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err = o.Insert(item)
|
|
|
+ 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 = 1
|
|
|
+ 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(item) //写入订单信息
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = o.Insert(itemOrderAction) // 写入订单操作信息
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
return
|
|
|
}
|