order.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. package model
  2. import (
  3. "encoding/json"
  4. "go-common/app/common/openplatform/encoding"
  5. "go-common/app/service/openplatform/ticket-sales/api/grpc/type"
  6. "go-common/app/service/openplatform/ticket-sales/api/grpc/v1"
  7. "go-common/library/time"
  8. "github.com/gogo/protobuf/types"
  9. )
  10. //OrderMain 订单主表结构
  11. type OrderMain struct {
  12. OrderID int64 `json:"order_id"`
  13. UID string `json:"uid"`
  14. OrderType int16 `json:"order_type"`
  15. ItemID int64 `json:"item_id"`
  16. ItemInfo *_type.OrderItemInfo `json:"item_info"`
  17. Count int64 `json:"count"`
  18. TotalMoney int64 `json:"total_money"`
  19. PayMoney int64 `json:"pay_money"`
  20. ExpressFee int64 `json:"express_fee"`
  21. PayChannel int16 `json:"pay_channel"`
  22. PayTime int64 `json:"pay_time"`
  23. Source string `json:"source"`
  24. Status int16 `json:"status"`
  25. SubStatus int16 `json:"sub_status"`
  26. RefundStatus int16 `json:"refund_status"`
  27. IsDeleted int16 `json:"is_deleted"`
  28. CTime time.Time `json:"ctime"`
  29. MTime time.Time `json:"mtime"`
  30. }
  31. //OrderMainQuerier 订单表查询参数
  32. type OrderMainQuerier v1.ListOrdersRequest
  33. // OrderDetail 订单详情表信息
  34. type OrderDetail struct {
  35. OrderID int64 `json:"order_id"`
  36. Buyer string `json:"buyer"`
  37. Tel string `json:"tel"`
  38. PersonalID string `json:"personal_id"`
  39. ExpressCO string `json:"express_co"`
  40. ExpressNO string `json:"express_no"`
  41. ExpressType int16 `json:"express_type"`
  42. Remark string `json:"remark"`
  43. DeviceType int16 `json:"device_type"`
  44. IP []byte `json:"ip"`
  45. Coupon *_type.OrderCoupon `json:"coupon"`
  46. DeliverDetail *_type.OrderDeliver `json:"deliver_detail"`
  47. Detail *_type.OrderExtra `json:"detail"`
  48. MSource string `json:"msource"`
  49. CTime time.Time `json:"-"`
  50. MTime time.Time `json:"-"`
  51. }
  52. //OrderSKU order_sku表结构
  53. type OrderSKU _type.OrderSKU
  54. //OrderPayCharge 订单支付表结构
  55. type OrderPayCharge _type.OrderPayCharge
  56. //GetFields 获取order_main表所有字段,参数是需要排除的字段
  57. func (o *OrderMain) GetFields(except *types.FieldMask) []string {
  58. fields := []string{
  59. "order_id", "uid", "order_type", "item_id", "item_info",
  60. "count", "total_money", "express_fee", "pay_money", "pay_channel",
  61. "pay_time", "source", "status", "sub_status", "refund_status",
  62. "is_deleted", "ctime", "mtime",
  63. }
  64. if except != nil {
  65. lp := len(except.Paths)
  66. mExcept := make(map[string]bool, lp)
  67. for _, v := range except.Paths {
  68. mExcept[v] = true
  69. }
  70. res := make([]string, len(fields)-lp)
  71. i := 0
  72. for _, v := range fields {
  73. if ok := mExcept[v]; !ok {
  74. res[i] = v
  75. i++
  76. }
  77. }
  78. return res
  79. }
  80. return fields
  81. }
  82. //GetFields 获取order_detail字段名称
  83. func (o *OrderDetail) GetFields(except *types.FieldMask) []string {
  84. fields := []string{
  85. "order_id", "buyer", "tel", "personal_id", "express_co",
  86. "express_no", "express_type", "remark", "device_type", "ip",
  87. "coupon", "deliver_detail", "detail", "msource", "ctime",
  88. "mtime",
  89. }
  90. if except != nil {
  91. lp := len(except.Paths)
  92. mExcept := make(map[string]bool, lp)
  93. for _, v := range except.Paths {
  94. mExcept[v] = true
  95. }
  96. res := make([]string, len(fields)-lp)
  97. i := 0
  98. for _, v := range fields {
  99. if ok := mExcept[v]; !ok {
  100. res[i] = v
  101. i++
  102. }
  103. }
  104. return res
  105. }
  106. return fields
  107. }
  108. //GetFields 获取order_sku对象的字段名
  109. func (o *OrderSKU) GetFields(except *types.FieldMask) []string {
  110. fields := []string{
  111. "order_id", "sku_id", "count", "origin_price", "price",
  112. "seat_ids", "ticket_type", "discounts", "ctime", "mtime",
  113. }
  114. if except != nil {
  115. lp := len(except.Paths)
  116. mExcept := make(map[string]bool, lp)
  117. for _, v := range except.Paths {
  118. mExcept[v] = true
  119. }
  120. res := make([]string, len(fields)-lp)
  121. i := 0
  122. for _, v := range fields {
  123. if ok := mExcept[v]; !ok {
  124. res[i] = v
  125. i++
  126. }
  127. }
  128. return res
  129. }
  130. return fields
  131. }
  132. //GetFields 获取order_pay_charge对象的字段名
  133. func (o *OrderPayCharge) GetFields(except *types.FieldMask) []string {
  134. fields := []string{
  135. "order_id", "charge_id", "channel", "paid", "refunded",
  136. "ctime", "mtime",
  137. }
  138. if except != nil {
  139. lp := len(except.Paths)
  140. mExcept := make(map[string]bool, lp)
  141. for _, v := range except.Paths {
  142. mExcept[v] = true
  143. }
  144. res := make([]string, len(fields)-lp)
  145. i := 0
  146. for _, v := range fields {
  147. if ok := mExcept[v]; !ok {
  148. res[i] = v
  149. i++
  150. }
  151. }
  152. return res
  153. }
  154. return fields
  155. }
  156. //GetPtrs 获取order_main对象指针
  157. // 如果设置vptr参数,会把struct指针替换成string指针,并在vptr保存原struct指针(as value)和它在返回数组中的下标(as key)
  158. func (o *OrderMain) GetPtrs(fields *types.FieldMask, vptr map[int]interface{}) []interface{} {
  159. ptrs := map[string]interface{}{
  160. "order_id": &o.OrderID,
  161. "uid": &o.UID,
  162. "order_type": &o.OrderType,
  163. "item_id": &o.ItemID,
  164. "item_info": &o.ItemInfo,
  165. "count": &o.Count,
  166. "total_money": &o.TotalMoney,
  167. "express_fee": &o.ExpressFee,
  168. "pay_money": &o.PayMoney,
  169. "pay_channel": &o.PayChannel,
  170. "pay_time": &o.PayTime,
  171. "source": &o.Source,
  172. "status": &o.Status,
  173. "sub_status": &o.SubStatus,
  174. "refund_status": &o.RefundStatus,
  175. "is_deleted": &o.IsDeleted,
  176. "ctime": &o.CTime,
  177. "mtime": &o.MTime,
  178. }
  179. if fields == nil {
  180. fields = &types.FieldMask{Paths: o.GetFields(nil)}
  181. }
  182. ret := make([]interface{}, len(fields.Paths))
  183. i := 0
  184. for _, f := range fields.Paths {
  185. if vptr != nil && f == "item_info" {
  186. var s string
  187. ret[i] = &s
  188. vptr[i] = ptrs[f]
  189. } else {
  190. ret[i] = ptrs[f]
  191. }
  192. i++
  193. }
  194. return ret
  195. }
  196. //GetPtrs 获取order_detail对象指针
  197. func (o *OrderDetail) GetPtrs(fields *types.FieldMask, vptr map[int]interface{}) []interface{} {
  198. ptrs := map[string]interface{}{
  199. "order_id": &o.OrderID,
  200. "buyer": &o.Buyer,
  201. "tel": &o.Tel,
  202. "personal_id": &o.PersonalID,
  203. "express_co": &o.ExpressCO,
  204. "express_no": &o.ExpressNO,
  205. "express_type": &o.ExpressType,
  206. "remark": &o.Remark,
  207. "device_type": &o.DeviceType,
  208. "ip": &o.IP,
  209. "coupon": &o.Coupon,
  210. "deliver_detail": &o.DeliverDetail,
  211. "detail": &o.Detail,
  212. "msource": &o.MSource,
  213. "ctime": &o.CTime,
  214. "mtime": &o.MTime,
  215. }
  216. if fields == nil {
  217. fields = &types.FieldMask{Paths: o.GetFields(nil)}
  218. }
  219. ret := make([]interface{}, len(fields.Paths))
  220. i := 0
  221. for _, f := range fields.Paths {
  222. if vptr != nil && (f == "coupon" || f == "deliver_detail" || f == "detail") {
  223. var s string
  224. ret[i] = &s
  225. vptr[i] = ptrs[f]
  226. } else {
  227. ret[i] = ptrs[f]
  228. }
  229. i++
  230. }
  231. return ret
  232. }
  233. //GetPtrs 获取order_sku对象的字段指针
  234. func (o *OrderSKU) GetPtrs(fields *types.FieldMask, vptr map[int]interface{}) []interface{} {
  235. ptrs := map[string]interface{}{
  236. "order_id": &o.OrderID,
  237. "sku_id": &o.SKUID,
  238. "count": &o.Count,
  239. "origin_price": &o.OriginPrice,
  240. "price": &o.Price,
  241. "seat_ids": &o.SeatIDs,
  242. "ticket_type": &o.TicketType,
  243. "discounts": &o.Discounts,
  244. "ctime": &o.CTime,
  245. "mtime": &o.MTime,
  246. }
  247. if fields == nil {
  248. fields = &types.FieldMask{Paths: o.GetFields(nil)}
  249. }
  250. ret := make([]interface{}, len(fields.Paths))
  251. i := 0
  252. for _, f := range fields.Paths {
  253. if vptr != nil && (f == "discounts" || f == "seat_ids") {
  254. var s string
  255. ret[i] = &s
  256. vptr[i] = ptrs[f]
  257. } else {
  258. ret[i] = ptrs[f]
  259. }
  260. i++
  261. }
  262. return ret
  263. }
  264. //GetPtrs 获取order_pay_charge对象的字段指针
  265. func (o *OrderPayCharge) GetPtrs(fields *types.FieldMask, vptr map[int]interface{}) []interface{} {
  266. ptrs := map[string]interface{}{
  267. "order_id": &o.OrderID,
  268. "charge_id": &o.ChargeID,
  269. "channel": &o.Channel,
  270. "paid": &o.Paid,
  271. "refunded": &o.Refunded,
  272. "ctime": &o.CTime,
  273. "mtime": &o.MTime,
  274. }
  275. if fields == nil {
  276. fields = &types.FieldMask{Paths: o.GetFields(nil)}
  277. }
  278. ret := make([]interface{}, len(fields.Paths))
  279. i := 0
  280. for _, f := range fields.Paths {
  281. if vptr != nil && f == "discounts" {
  282. var s string
  283. ret[i] = &s
  284. vptr[i] = ptrs[f]
  285. } else {
  286. ret[i] = ptrs[f]
  287. }
  288. i++
  289. }
  290. return ret
  291. }
  292. //GetVals 获取order_main对象里的值
  293. func (o *OrderMain) GetVals(fields *types.FieldMask, asString bool) []interface{} {
  294. vals := map[string]interface{}{
  295. "order_id": o.OrderID,
  296. "uid": o.UID,
  297. "order_type": o.OrderType,
  298. "item_id": o.ItemID,
  299. "item_info": o.ItemInfo,
  300. "count": o.Count,
  301. "total_money": o.TotalMoney,
  302. "express_fee": o.ExpressFee,
  303. "pay_money": o.PayMoney,
  304. "pay_channel": o.PayChannel,
  305. "pay_time": o.PayTime,
  306. "source": o.Source,
  307. "status": o.Status,
  308. "sub_status": o.SubStatus,
  309. "refund_status": o.RefundStatus,
  310. "is_deleted": o.IsDeleted,
  311. "ctime": o.CTime,
  312. "mtime": o.MTime,
  313. }
  314. if fields == nil {
  315. fields = &types.FieldMask{Paths: o.GetFields(nil)}
  316. }
  317. ret := make([]interface{}, len(fields.Paths))
  318. i := 0
  319. for _, f := range fields.Paths {
  320. if asString && f == "item_info" {
  321. if b, err := json.Marshal(vals[f]); err == nil {
  322. ret[i] = string(b)
  323. }
  324. } else {
  325. ret[i] = vals[f]
  326. }
  327. i++
  328. }
  329. return ret
  330. }
  331. //GetVals 获取order_detail对象字段的值
  332. func (o *OrderDetail) GetVals(fields *types.FieldMask, asString bool) []interface{} {
  333. vals := map[string]interface{}{
  334. "order_id": o.OrderID,
  335. "buyer": o.Buyer,
  336. "tel": o.Tel,
  337. "personal_id": o.PersonalID,
  338. "express_co": o.ExpressCO,
  339. "express_no": o.ExpressNO,
  340. "express_type": o.ExpressType,
  341. "remark": o.Remark,
  342. "device_type": o.DeviceType,
  343. "ip": o.IP,
  344. "coupon": o.Coupon,
  345. "deliver_detail": o.DeliverDetail,
  346. "detail": o.Detail,
  347. "msource": o.MSource,
  348. "ctime": o.CTime,
  349. "mtime": o.MTime,
  350. }
  351. if fields == nil {
  352. fields = &types.FieldMask{Paths: o.GetFields(nil)}
  353. }
  354. ret := make([]interface{}, len(fields.Paths))
  355. i := 0
  356. for _, f := range fields.Paths {
  357. if asString && (f == "coupon" || f == "deliver_detail" || f == "detail") {
  358. if b, err := json.Marshal(vals[f]); err == nil {
  359. ret[i] = string(b)
  360. }
  361. } else {
  362. ret[i] = vals[f]
  363. }
  364. i++
  365. }
  366. return ret
  367. }
  368. //GetVals 获取order_sku字段的值
  369. func (o *OrderSKU) GetVals(fields *types.FieldMask, asString bool) []interface{} {
  370. vals := map[string]interface{}{
  371. "order_id": o.OrderID,
  372. "sku_id": o.SKUID,
  373. "count": o.Count,
  374. "origin_price": o.OriginPrice,
  375. "price": o.Price,
  376. "seat_ids": o.SeatIDs,
  377. "ticket_type": o.TicketType,
  378. "discounts": o.Discounts,
  379. "ctime": o.CTime,
  380. "mtime": o.MTime,
  381. }
  382. if fields == nil {
  383. fields = &types.FieldMask{Paths: o.GetFields(nil)}
  384. }
  385. ret := make([]interface{}, len(fields.Paths))
  386. i := 0
  387. for _, f := range fields.Paths {
  388. if asString && (f == "discounts" || f == "seat_ids") {
  389. if b, err := json.Marshal(vals[f]); err == nil {
  390. ret[i] = string(b)
  391. }
  392. } else {
  393. ret[i] = vals[f]
  394. }
  395. i++
  396. }
  397. return ret
  398. }
  399. func (o *OrderDetail) getEncryptPtrs() []*string {
  400. res := make([]*string, 3)
  401. res[0] = &o.Tel
  402. res[1] = &o.PersonalID
  403. if o.DeliverDetail != nil {
  404. res[2] = &o.DeliverDetail.Tel
  405. }
  406. return res
  407. }
  408. //Encrypt 加密order_detail的字段
  409. func (o *OrderDetail) Encrypt(c *encoding.EncryptConfig) {
  410. for _, p := range o.getEncryptPtrs() {
  411. if p != nil {
  412. s, _ := encoding.Encrypt(*p, c)
  413. *p = s
  414. }
  415. }
  416. }
  417. //Decrypt 解密order_detail字段
  418. func (o *OrderDetail) Decrypt(c *encoding.EncryptConfig) {
  419. for _, p := range o.getEncryptPtrs() {
  420. if p != nil {
  421. s, _ := encoding.Decrypt(*p, c)
  422. *p = s
  423. }
  424. }
  425. }
  426. //GetSettleOrdersRequest 获取结算订单请求
  427. type GetSettleOrdersRequest struct {
  428. Date string `form:"date" validate:"required"`
  429. Ref byte `form:"ref"`
  430. ExtParams string `form:"extParams" validate:"omitempty,numeric"`
  431. PageSize int `form:"pagesize"`
  432. }
  433. //SettleOrder 获取结算订单返回
  434. type SettleOrder struct {
  435. ID int64 `json:"-"`
  436. OrderID int64 `json:"order_id"`
  437. RefID int64 `json:"ref_id"`
  438. RefundApplyTime time.Time `json:"-"`
  439. }
  440. //SettleOrders 获取结算订单返回
  441. type SettleOrders struct {
  442. Data []*SettleOrder `json:"data"`
  443. ExtParams string `json:"extParams"`
  444. }