order.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. StartDate time.Time `comment:"开始时间"`
  100. EndDate time.Time `comment:"结束时间"`
  101. }
  102. type CygxOrderAction struct {
  103. ActionId int64 `orm:"column(action_id);pk"` // 动作id
  104. Action string // 动作内容
  105. OrderStatus int // 订单状态,0:已取消、1:待支付、2:已支付、3:已退款
  106. OrderStatusText string // 订单状态名称
  107. OrderCode string // 订单编号
  108. UserId int // 用户ID
  109. Mobile string // 手机号
  110. Email string // 邮箱
  111. CompanyId int // 公司ID
  112. CompanyName string // 公司名称
  113. RealName string // 用户实际名称
  114. SellerName string // 所属销售
  115. CreateTime time.Time // 创建时间
  116. ModifyTime time.Time // 修改时间
  117. RegisterPlatform int // 来源 1小程序,2:网页
  118. AdminId int // 管理员ID
  119. AdminName string // 管理员姓名
  120. }
  121. type OrderListResp struct {
  122. OrderCode string `comment:"订单编号"`
  123. OrderMoney float64 `comment:"订单总价"`
  124. CreateTime string `comment:"创建时间"`
  125. SourceId int `comment:"来源ID"`
  126. Source string `comment:"来源\n报告 :article\n活动 :activity"`
  127. SourceTitle string `comment:"来源名称,活动或者报告标题"`
  128. OrderStatus int `comment:"订单状态码"`
  129. OrderStatusText string `comment:"订单状态描述"`
  130. LabelKeywordImgLink string `comment:"标签关键词ico"`
  131. LabelKeyword string `comment:"标签关键词"`
  132. StartDate string `comment:"开始日期"`
  133. EndDate string `comment:"结束日期"`
  134. }
  135. type UserOrderListResp struct {
  136. Paging *paging.PagingItem `description:"分页数据"`
  137. List []*OrderListResp
  138. }
  139. type PayEdOrderDetailResp struct {
  140. OrderCode string `comment:"订单编号"`
  141. OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
  142. EndDate string `comment:"结束日期"`
  143. OrderStatus int `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
  144. SourceId int `comment:"来源ID"`
  145. Source string `comment:"来源\n报告 :article\n活动 :activity"`
  146. IsPublicActivitie bool `comment:"是否是公开活动"`
  147. IsSignUp bool `comment:"是否自动报名"`
  148. }
  149. // 添加
  150. func AddCygxOrder(item *CygxOrder) (err error) {
  151. o, err := orm.NewOrm().Begin()
  152. if err != nil {
  153. return
  154. }
  155. defer func() {
  156. fmt.Println(err)
  157. if err == nil {
  158. o.Commit()
  159. } else {
  160. o.Rollback()
  161. }
  162. }()
  163. item.OrderStatus = 1 // 初始状态待支付
  164. itemOrderAction := new(CygxOrderAction)
  165. itemOrderAction.Action = "创建订单"
  166. itemOrderAction.OrderStatus = 1
  167. itemOrderAction.OrderStatusText = "待支付"
  168. itemOrderAction.OrderCode = item.OrderCode
  169. itemOrderAction.UserId = item.UserId
  170. itemOrderAction.Mobile = item.Mobile
  171. itemOrderAction.Email = item.Email
  172. itemOrderAction.CompanyId = item.CompanyId
  173. itemOrderAction.CompanyName = item.CompanyName
  174. itemOrderAction.RealName = item.RealName
  175. itemOrderAction.SellerName = item.SellerName
  176. itemOrderAction.CreateTime = time.Now()
  177. itemOrderAction.ModifyTime = time.Now()
  178. itemOrderAction.RegisterPlatform = item.RegisterPlatform
  179. _, err = o.Insert(item) //写入订单信息
  180. if err != nil {
  181. return
  182. }
  183. _, err = o.Insert(itemOrderAction) // 写入订单操作信息
  184. if err != nil {
  185. return
  186. }
  187. return
  188. }
  189. // 添加
  190. func CancelCygxOrder(item *CygxOrder) (err error) {
  191. o, err := orm.NewOrm().Begin()
  192. if err != nil {
  193. return
  194. }
  195. defer func() {
  196. fmt.Println(err)
  197. if err == nil {
  198. o.Commit()
  199. } else {
  200. o.Rollback()
  201. }
  202. }()
  203. itemOrderAction := new(CygxOrderAction)
  204. itemOrderAction.Action = "取消订单"
  205. itemOrderAction.OrderStatus = 0
  206. itemOrderAction.OrderStatusText = "已取消"
  207. itemOrderAction.OrderCode = item.OrderCode
  208. itemOrderAction.UserId = item.UserId
  209. itemOrderAction.Mobile = item.Mobile
  210. itemOrderAction.Email = item.Email
  211. itemOrderAction.CompanyId = item.CompanyId
  212. itemOrderAction.CompanyName = item.CompanyName
  213. itemOrderAction.RealName = item.RealName
  214. itemOrderAction.SellerName = item.SellerName
  215. itemOrderAction.CreateTime = time.Now()
  216. itemOrderAction.ModifyTime = time.Now()
  217. itemOrderAction.RegisterPlatform = item.RegisterPlatform
  218. _, err = o.Insert(itemOrderAction) // 写入订单操作信息
  219. if err != nil {
  220. return
  221. }
  222. updateParams := make(map[string]interface{})
  223. updateParams["OrderStatus"] = 0
  224. updateParams["ModifyTime"] = item.ModifyTime
  225. ptrStructOrTableName := "cygx_order"
  226. whereParam := map[string]interface{}{"order_code": item.OrderCode}
  227. qs := o.QueryTable(ptrStructOrTableName)
  228. for expr, exprV := range whereParam {
  229. qs = qs.Filter(expr, exprV)
  230. }
  231. _, err = qs.Update(updateParams)
  232. if err != nil {
  233. return
  234. }
  235. return
  236. }
  237. // 根据订单编号修改
  238. func UpdateCygxOrder(item *CygxOrder, oldOrderCode string) (err error) {
  239. o := orm.NewOrm()
  240. updateParams := make(map[string]interface{})
  241. updateParams["SourceId"] = item.SourceId
  242. updateParams["Source"] = item.Source
  243. updateParams["SourceTitle"] = item.SourceTitle
  244. updateParams["OutTradeNo"] = item.OutTradeNo
  245. updateParams["GoodsMoney"] = item.GoodsMoney
  246. updateParams["OrderMoney"] = item.OrderMoney
  247. updateParams["ShareId"] = item.ShareId
  248. updateParams["ShareName"] = item.ShareName
  249. updateParams["ModifyTime"] = item.ModifyTime
  250. ptrStructOrTableName := "cygx_order"
  251. whereParam := map[string]interface{}{"order_code": oldOrderCode}
  252. qs := o.QueryTable(ptrStructOrTableName)
  253. for expr, exprV := range whereParam {
  254. qs = qs.Filter(expr, exprV)
  255. }
  256. _, err = qs.Update(updateParams)
  257. if err != nil {
  258. return
  259. }
  260. return
  261. }
  262. func GetCygxOrderList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxOrderResp, err error) {
  263. o := orm.NewOrm()
  264. sql := `SELECT *
  265. FROM
  266. cygx_order
  267. WHERE 1 = 1 ` + condition
  268. sql += ` LIMIT ?,? `
  269. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  270. return
  271. }
  272. // 根据订单编号获取订单详情
  273. func GetCygxOrderDetailByOrderCode(orderCode string) (item *CygxOrder, err error) {
  274. o := orm.NewOrm()
  275. sql := `SELECT * FROM cygx_order WHERE order_code = ? `
  276. err = o.Raw(sql, orderCode).QueryRow(&item)
  277. return
  278. }
  279. // 获取数量
  280. func GetCygxOrderCount(condition string, pars []interface{}) (count int, err error) {
  281. o := orm.NewOrm()
  282. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_order WHERE 1= 1 ` + condition
  283. err = o.Raw(sqlCount, pars).QueryRow(&count)
  284. return
  285. }