123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- package order
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- type WxNativeApiResp struct {
- CodeUrl string `comment:"微信支付二维码链接"`
- OrderCode string `comment:"订单编号"`
- PayTimeCountdown int `description:"支付时间倒计时"`
- }
- // PrepayWithRequestPaymentResponse 预下单ID,并包含了调起支付的请求参数
- type PrepayWithRequestPaymentResponse struct {
- PrepayId string // 预支付交易会话标识
- Appid string // 应用ID
- TimeStamp string // 时间戳
- NonceStr string // 随机字符串
- Package string // 订单详情扩展字符串
- SignType string // 签名方式
- PaySign string // 签名
- }
- type CygxOrderAddReq struct {
- GoodsId int `description:"商品ID"`
- Source string `description:"资源(文章、活动)"`
- SourceId int `description:"资源ID"`
- InviteShareCode string `description:"销售账号邀请码"`
- }
- type CygxOrderCancelReq struct {
- OrderCode string `comment:"订单编号"`
- }
- type CygxOrder struct {
- OrderId int `orm:"column(order_id);pk";comment:"订单id"`
- OrderCode string `comment:"订单编号"`
- OutTradeNo 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:单场付费订单"`
- ShareId int `comment:"分享人ID"`
- ShareName string `comment:"分享人姓名"`
- StartDate time.Time `comment:"开始时间"`
- EndDate time.Time `comment:"结束时间"`
- }
- 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:网页"`
- PlaySeconds string `description:"音视频时长"`
- 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 // 管理员姓名
- }
- type OrderListResp struct {
- OrderCode string `comment:"订单编号"`
- OrderMoney float64 `comment:"订单总价"`
- CreateTime string `comment:"创建时间"`
- SourceId int `comment:"来源ID"`
- Source string `comment:"来源\n报告 :article\n活动 :activity"`
- SourceTitle string `comment:"来源名称,活动或者报告标题"`
- OrderStatus int `comment:"订单状态码"`
- OrderStatusText string `comment:"订单状态描述"`
- LabelKeywordImgLink string `comment:"标签关键词ico"`
- LabelKeyword string `comment:"标签关键词"`
- PlaySeconds string `description:"音视频时长"`
- StartDate string `comment:"开始日期"`
- EndDate string `comment:"结束日期"`
- }
- type UserOrderListResp struct {
- Paging *paging.PagingItem `description:"分页数据"`
- List []*OrderListResp
- }
- type PayEdOrderDetailResp struct {
- OrderCode string `comment:"订单编号"`
- OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
- EndDate string `comment:"结束日期"`
- OrderStatus int `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
- SourceId int `comment:"来源ID"`
- Source string `comment:"来源\n报告 :article\n活动 :activity"`
- IsPublicActivitie bool `comment:"是否是公开活动"`
- IsSignUp bool `comment:"是否自动报名"`
- }
- // 添加
- func AddCygxOrder(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()
- }
- }()
- item.OrderStatus = 1 // 初始状态待支付
- 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
- }
- // 添加
- 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
- }
- // 根据订单编号修改
- func UpdateCygxOrder(item *CygxOrder, oldOrderCode string) (err error) {
- o := orm.NewOrm()
- updateParams := make(map[string]interface{})
- updateParams["SourceId"] = item.SourceId
- updateParams["Source"] = item.Source
- updateParams["SourceTitle"] = item.SourceTitle
- updateParams["OutTradeNo"] = item.OutTradeNo
- updateParams["GoodsMoney"] = item.GoodsMoney
- updateParams["OrderMoney"] = item.OrderMoney
- updateParams["ShareId"] = item.ShareId
- updateParams["ShareName"] = item.ShareName
- updateParams["ModifyTime"] = item.ModifyTime
- ptrStructOrTableName := "cygx_order"
- whereParam := map[string]interface{}{"order_code": oldOrderCode}
- qs := o.QueryTable(ptrStructOrTableName)
- for expr, exprV := range whereParam {
- qs = qs.Filter(expr, exprV)
- }
- _, err = qs.Update(updateParams)
- if err != nil {
- return
- }
- return
- }
- func GetCygxOrderList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxOrderResp, 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 GetCygxOrderDetailByOrderCode(orderCode string) (item *CygxOrder, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM cygx_order WHERE order_code = ? `
- err = o.Raw(sql, orderCode).QueryRow(&item)
- return
- }
- // 获取数量
- func GetCygxOrderCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_order WHERE 1= 1 ` + condition
- err = o.Raw(sqlCount, pars).QueryRow(&count)
- return
- }
|