package order //用户虚拟资产表 import ( "fmt" "github.com/beego/beego/v2/client/orm" "hongze/hongze_web_mfyx/utils" "time" ) type CygxOrderVirtualAsset struct { OrderVirtualAssetsId int `orm:"column(order_virtual_assets_id);pk";comment:"订单支付ID"` OrderCode 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:"修改时间"` SourceId int `comment:"来源ID"` Source string `comment:"来源\n报告 :article\n活动 :activity"` } // 添加 func AddCygxOrderVirtualAsset(item *CygxOrderVirtualAsset, itemOrder *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 = 2 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 = utils.REGISTER_PLATFORM updateParams := make(map[string]interface{}) updateParams["PayTime"] = itemOrder.PayTime updateParams["PayMoney"] = itemOrder.PayMoney updateParams["OrderStatus"] = itemOrder.OrderStatus updateParams["OutTradeCode"] = itemOrder.OutTradeCode updateParams["ModifyTime"] = item.ModifyTime updateParams["PaymentType"] = 1 ptrStructOrTableName := "cygx_order" whereParam := map[string]interface{}{"order_code": itemOrder.OrderCode} qs := o.QueryTable(ptrStructOrTableName) for expr, exprV := range whereParam { qs = qs.Filter(expr, exprV) } _, err = qs.Update(updateParams) // 修改订单状态 if err != nil { return } _, err = o.Insert(itemOrderAction) // 写入订单操作信息 if err != nil { return } _, err = o.Insert(item) //写入用户用户虚拟资产表 if err != nil { return } return } // 获取数量 func GetCygxOrderVirtualAssetdCount(condition string, pars []interface{}) (count int, err error) { o := orm.NewOrm() sqlCount := ` SELECT COUNT(1) AS count FROM cygx_order_virtual_asset WHERE 1= 1 ` + condition err = o.Raw(sqlCount, pars).QueryRow(&count) return } // 获取数量 func GetCygxOrderVirtualAssetdCountByVivo(sourceId, userId int) (count int, err error) { o := orm.NewOrm() sqlCount := ` SELECT COUNT(1) AS count FROM cygx_order_virtual_asset WHERE source IN ('activityvideo','activityvoice') AND source_id = ? AND user_id = ? ` err = o.Raw(sqlCount, sourceId, userId).QueryRow(&count) return } // 获取购买的单场活动 func GetCygxOrderVirtualAssetActivityList(sourceIds []int, mobile string) (items []*CygxOrderVirtualAsset, err error) { lenArr := len(sourceIds) if lenArr == 0 { return } o := orm.NewOrm() sql := `SELECT source_id FROM cygx_order_virtual_asset WHERE 1=1 AND source = 'activity' AND mobile= ? AND source_id IN (` + utils.GetOrmInReplace(lenArr) + `) ` _, err = o.Raw(sql, mobile, sourceIds).QueryRows(&items) return } // 移除用户活动权限记录 func RemoveCygxOrderVirtualAsset(item *CygxOrderVirtualAsset, itemOrder *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 = 3 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 = utils.REGISTER_PLATFORM updateParams := make(map[string]interface{}) updateParams["OrderStatus"] = itemOrder.OrderStatus updateParams["ModifyTime"] = item.ModifyTime ptrStructOrTableName := "cygx_order" whereParam := map[string]interface{}{"order_code": itemOrder.OrderCode} qs := o.QueryTable(ptrStructOrTableName) for expr, exprV := range whereParam { qs = qs.Filter(expr, exprV) } _, err = qs.Update(updateParams) // 修改订单状态 if err != nil { return } _, err = o.Insert(itemOrderAction) // 写入订单操作信息 if err != nil { return } sql := ` DELETE FROM cygx_order_virtual_asset WHERE order_code =? ` // 删除原有的持卡信息 _, err = o.Raw(sql, item.OrderCode).Exec() if err != nil { return } return }