order.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. package order
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type WxNativeApiResp struct {
  9. CodeUrl string `comment:"微信支付二维码链接"`
  10. OrderCode string `comment:"订单编号"`
  11. PayTimeCountdown int `description:"支付时间倒计时"`
  12. }
  13. // PrepayWithRequestPaymentResponse 预下单ID,并包含了调起支付的请求参数
  14. type PrepayWithRequestPaymentResponse struct {
  15. PrepayId string // 预支付交易会话标识
  16. Appid string // 应用ID
  17. TimeStamp string // 时间戳
  18. NonceStr string // 随机字符串
  19. Package string // 订单详情扩展字符串
  20. SignType string // 签名方式
  21. PaySign string // 签名
  22. }
  23. type CygxOrderAddReq struct {
  24. GoodsId int `description:"商品ID"`
  25. Source string `description:"资源(文章、活动)"`
  26. SourceId int `description:"资源ID"`
  27. InviteShareCode string `description:"销售账号邀请码"`
  28. }
  29. type CygxOrderCancelReq struct {
  30. OrderCode string `comment:"订单编号"`
  31. }
  32. type CygxOrder struct {
  33. OrderId int `orm:"column(order_id);pk";comment:"订单id"`
  34. OrderCode string `comment:"订单编号"`
  35. OutTradeNo string `comment:"【商户订单号】 商户系统内部订单号"`
  36. OutTradeCode string `comment:"外部交易号"`
  37. PaymentType int `comment:"支付类型。取值范围:1微信支付,2支付宝支付。"`
  38. GoodsName string `comment:"商品名称"`
  39. GoodsId int `comment:"商品ID"`
  40. BuyerInvoice string `comment:"买家发票信息"`
  41. GoodsMoney float64 `comment:"商品总价"`
  42. OrderMoney float64 `comment:"订单总价"`
  43. Point int `comment:"订单消耗积分"`
  44. PointMoney float64 `comment:"订单消耗积分抵多少钱"`
  45. PayMoney float64 `comment:"订单实付金额"`
  46. RefundTime time.Time `comment:"订单退款时间"`
  47. RefundMoney float64 `comment:"订单退款金额"`
  48. OrderStatus int `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
  49. PayTime time.Time `comment:"订单付款时间"`
  50. SourceId int `comment:"来源ID"`
  51. Source string `comment:"来源\n报告 :article\n活动 :activity"`
  52. SourceTitle string `comment:"来源名称,活动或者报告标题"`
  53. UserId int `comment:"用户ID"`
  54. Mobile string `comment:"手机号"`
  55. Email string `comment:"邮箱"`
  56. CompanyId int `comment:"公司ID"`
  57. CompanyName string `comment:"公司名称"`
  58. RealName string `comment:"用户实际名称"`
  59. SellerName string `comment:"所属销售"`
  60. SellerId int `comment:"所属销售Id"`
  61. CreateTime time.Time `comment:"创建时间"`
  62. ModifyTime time.Time `comment:"修改时间"`
  63. RegisterPlatform int `comment:"来源 1小程序,2:网页"`
  64. OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
  65. ShareId int `comment:"分享人ID"`
  66. ShareName string `comment:"分享人姓名"`
  67. StartDate time.Time `comment:"开始时间"`
  68. EndDate time.Time `comment:"结束时间"`
  69. }
  70. type CygxOrderResp struct {
  71. OrderId int `orm:"column(order_id);pk";comment:"订单id"`
  72. OrderCode string `comment:"订单编号"`
  73. OutTradeCode string `comment:"外部交易号"`
  74. PaymentType int `comment:"支付类型。取值范围:1微信支付,2支付宝支付。"`
  75. GoodsName string `comment:"商品名称"`
  76. GoodsId int `comment:"商品ID"`
  77. BuyerInvoice string `comment:"买家发票信息"`
  78. GoodsMoney float64 `comment:"商品总价"`
  79. OrderMoney float64 `comment:"订单总价"`
  80. Point int `comment:"订单消耗积分"`
  81. PointMoney float64 `comment:"订单消耗积分抵多少钱"`
  82. PayMoney float64 `comment:"订单实付金额"`
  83. RefundMoney float64 `comment:"订单退款金额"`
  84. OrderStatus int `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
  85. PayTime time.Time `comment:"订单付款时间"`
  86. SourceId int `comment:"来源ID"`
  87. Source string `comment:"来源\n报告 :article\n活动 :activity"`
  88. SourceTitle string `comment:"来源名称,活动或者报告标题"`
  89. UserId int `comment:"用户ID"`
  90. Mobile string `comment:"手机号"`
  91. Email string `comment:"邮箱"`
  92. CompanyId int `comment:"公司ID"`
  93. CompanyName string `comment:"公司名称"`
  94. RealName string `comment:"用户实际名称"`
  95. SellerName string `comment:"所属销售"`
  96. CreateTime time.Time `comment:"创建时间"`
  97. ModifyTime time.Time `comment:"修改时间"`
  98. RegisterPlatform int `comment:"来源 1小程序,2:网页"`
  99. PlaySeconds string `description:"音视频时长"`
  100. OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
  101. StartDate time.Time `comment:"开始时间"`
  102. EndDate time.Time `comment:"结束时间"`
  103. }
  104. type CygxOrderAction struct {
  105. ActionId int64 `orm:"column(action_id);pk"` // 动作id
  106. Action string // 动作内容
  107. OrderStatus int // 订单状态,0:已取消、1:待支付、2:已支付、3:已退款
  108. OrderStatusText string // 订单状态名称
  109. OrderCode string // 订单编号
  110. UserId int // 用户ID
  111. Mobile string // 手机号
  112. Email string // 邮箱
  113. CompanyId int // 公司ID
  114. CompanyName string // 公司名称
  115. RealName string // 用户实际名称
  116. SellerName string // 所属销售
  117. CreateTime time.Time // 创建时间
  118. ModifyTime time.Time // 修改时间
  119. RegisterPlatform int // 来源 1小程序,2:网页
  120. AdminId int // 管理员ID
  121. AdminName string // 管理员姓名
  122. }
  123. type OrderListResp struct {
  124. OrderCode string `comment:"订单编号"`
  125. OrderMoney float64 `comment:"订单总价"`
  126. CreateTime string `comment:"创建时间"`
  127. SourceId int `comment:"来源ID"`
  128. Source string `comment:"来源\n报告 :article\n活动 :activity"`
  129. SourceTitle string `comment:"来源名称,活动或者报告标题"`
  130. OrderStatus int `comment:"订单状态码"`
  131. OrderStatusText string `comment:"订单状态描述"`
  132. LabelKeywordImgLink string `comment:"标签关键词ico"`
  133. LabelKeyword string `comment:"标签关键词"`
  134. PlaySeconds string `description:"音视频时长"`
  135. StartDate string `comment:"开始日期"`
  136. EndDate string `comment:"结束日期"`
  137. }
  138. type UserOrderListResp struct {
  139. Paging *paging.PagingItem `description:"分页数据"`
  140. List []*OrderListResp
  141. }
  142. type PayEdOrderDetailResp struct {
  143. OrderCode string `comment:"订单编号"`
  144. OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
  145. EndDate string `comment:"结束日期"`
  146. OrderStatus int `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
  147. SourceId int `comment:"来源ID"`
  148. Source string `comment:"来源\n报告 :article\n活动 :activity"`
  149. IsPublicActivitie bool `comment:"是否是公开活动"`
  150. IsSignUp bool `comment:"是否自动报名"`
  151. }
  152. // 添加
  153. func AddCygxOrder(item *CygxOrder) (err error) {
  154. o, err := orm.NewOrm().Begin()
  155. if err != nil {
  156. return
  157. }
  158. defer func() {
  159. fmt.Println(err)
  160. if err == nil {
  161. o.Commit()
  162. } else {
  163. o.Rollback()
  164. }
  165. }()
  166. item.OrderStatus = 1 // 初始状态待支付
  167. itemOrderAction := new(CygxOrderAction)
  168. itemOrderAction.Action = "创建订单"
  169. itemOrderAction.OrderStatus = 1
  170. itemOrderAction.OrderStatusText = "待支付"
  171. itemOrderAction.OrderCode = item.OrderCode
  172. itemOrderAction.UserId = item.UserId
  173. itemOrderAction.Mobile = item.Mobile
  174. itemOrderAction.Email = item.Email
  175. itemOrderAction.CompanyId = item.CompanyId
  176. itemOrderAction.CompanyName = item.CompanyName
  177. itemOrderAction.RealName = item.RealName
  178. itemOrderAction.SellerName = item.SellerName
  179. itemOrderAction.CreateTime = time.Now()
  180. itemOrderAction.ModifyTime = time.Now()
  181. itemOrderAction.RegisterPlatform = item.RegisterPlatform
  182. _, err = o.Insert(item) //写入订单信息
  183. if err != nil {
  184. return
  185. }
  186. _, err = o.Insert(itemOrderAction) // 写入订单操作信息
  187. if err != nil {
  188. return
  189. }
  190. return
  191. }
  192. // 添加
  193. func CancelCygxOrder(item *CygxOrder) (err error) {
  194. o, err := orm.NewOrm().Begin()
  195. if err != nil {
  196. return
  197. }
  198. defer func() {
  199. fmt.Println(err)
  200. if err == nil {
  201. o.Commit()
  202. } else {
  203. o.Rollback()
  204. }
  205. }()
  206. itemOrderAction := new(CygxOrderAction)
  207. itemOrderAction.Action = "取消订单"
  208. itemOrderAction.OrderStatus = 0
  209. itemOrderAction.OrderStatusText = "已取消"
  210. itemOrderAction.OrderCode = item.OrderCode
  211. itemOrderAction.UserId = item.UserId
  212. itemOrderAction.Mobile = item.Mobile
  213. itemOrderAction.Email = item.Email
  214. itemOrderAction.CompanyId = item.CompanyId
  215. itemOrderAction.CompanyName = item.CompanyName
  216. itemOrderAction.RealName = item.RealName
  217. itemOrderAction.SellerName = item.SellerName
  218. itemOrderAction.CreateTime = time.Now()
  219. itemOrderAction.ModifyTime = time.Now()
  220. itemOrderAction.RegisterPlatform = item.RegisterPlatform
  221. _, err = o.Insert(itemOrderAction) // 写入订单操作信息
  222. if err != nil {
  223. return
  224. }
  225. updateParams := make(map[string]interface{})
  226. updateParams["OrderStatus"] = 0
  227. updateParams["ModifyTime"] = item.ModifyTime
  228. ptrStructOrTableName := "cygx_order"
  229. whereParam := map[string]interface{}{"order_code": item.OrderCode}
  230. qs := o.QueryTable(ptrStructOrTableName)
  231. for expr, exprV := range whereParam {
  232. qs = qs.Filter(expr, exprV)
  233. }
  234. _, err = qs.Update(updateParams)
  235. if err != nil {
  236. return
  237. }
  238. return
  239. }
  240. // 根据订单编号修改
  241. func UpdateCygxOrder(item *CygxOrder, oldOrderCode string) (err error) {
  242. o := orm.NewOrm()
  243. updateParams := make(map[string]interface{})
  244. updateParams["SourceId"] = item.SourceId
  245. updateParams["Source"] = item.Source
  246. updateParams["SourceTitle"] = item.SourceTitle
  247. updateParams["OutTradeNo"] = item.OutTradeNo
  248. updateParams["GoodsMoney"] = item.GoodsMoney
  249. updateParams["OrderMoney"] = item.OrderMoney
  250. updateParams["ShareId"] = item.ShareId
  251. updateParams["ShareName"] = item.ShareName
  252. updateParams["ModifyTime"] = item.ModifyTime
  253. ptrStructOrTableName := "cygx_order"
  254. whereParam := map[string]interface{}{"order_code": oldOrderCode}
  255. qs := o.QueryTable(ptrStructOrTableName)
  256. for expr, exprV := range whereParam {
  257. qs = qs.Filter(expr, exprV)
  258. }
  259. _, err = qs.Update(updateParams)
  260. if err != nil {
  261. return
  262. }
  263. return
  264. }
  265. func GetCygxOrderList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxOrderResp, err error) {
  266. o := orm.NewOrm()
  267. sql := `SELECT *
  268. FROM
  269. cygx_order
  270. WHERE 1 = 1 ` + condition
  271. sql += ` LIMIT ?,? `
  272. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  273. return
  274. }
  275. // 根据订单编号获取订单详情
  276. func GetCygxOrderDetailByOrderCode(orderCode string) (item *CygxOrder, err error) {
  277. o := orm.NewOrm()
  278. sql := `SELECT * FROM cygx_order WHERE order_code = ? `
  279. err = o.Raw(sql, orderCode).QueryRow(&item)
  280. return
  281. }
  282. // 获取数量
  283. func GetCygxOrderCount(condition string, pars []interface{}) (count int, err error) {
  284. o := orm.NewOrm()
  285. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_order WHERE 1= 1 ` + condition
  286. err = o.Raw(sqlCount, pars).QueryRow(&count)
  287. return
  288. }