互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

586 lines
16 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package client
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hudongzhuanjia/controllers"
  6. "hudongzhuanjia/models"
  7. invitation_service "hudongzhuanjia/services/invitation"
  8. "hudongzhuanjia/utils"
  9. "hudongzhuanjia/utils/code"
  10. "hudongzhuanjia/utils/define"
  11. "github.com/ouxuanserver/osmanthuswine/src/core"
  12. )
  13. type OrderEntryCtl struct {
  14. controllers.AuthorCtl
  15. }
  16. // 用户查看所有商品
  17. func (t *OrderEntryCtl) List() {
  18. _type := t.GetAccountType()
  19. uid := t.GetAccountId()
  20. activityId := t.MustGetInt("activity_id")
  21. areaId := 0
  22. if _type == define.TYPE_ENTRYPEOPLE {
  23. entryPerson := models.OrderEntryPerson{}
  24. exist, err := models.Get(&entryPerson, uid)
  25. t.CheckErr(err)
  26. t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员信息异常")
  27. areaId = entryPerson.AreaId
  28. } else {
  29. areaId = t.MustGetInt("area_id")
  30. }
  31. goods, err := models.GetGoodsByActivityId(activityId, areaId)
  32. t.CheckErr(err)
  33. if _type == define.TYPE_H5USER {
  34. for index := range goods {
  35. url := fmt.Sprintf("%s/PcClient/Client/OrderEntryCtl/order?"+
  36. "user_id=%d&activity_id=%d&good_id=%d", define.HOST, uid, activityId, goods[index].Id)
  37. qrcode, err := utils.Qrcode2Base64(url)
  38. t.CheckErr(err)
  39. goods[index].Qrcode = qrcode
  40. }
  41. }
  42. t.JSON(map[string]interface{}{
  43. "list": goods,
  44. "total": len(goods),
  45. })
  46. }
  47. // 扫二维码下单
  48. func (t *OrderEntryCtl) Order() {
  49. userId := t.MustGetInt("user_id")
  50. goodId := t.MustGetInt("good_id")
  51. entryId := t.GetAccountId()
  52. entryPerson := models.OrderEntryPerson{}
  53. exist, err := models.Get(&entryPerson, entryId)
  54. t.CheckErr(err)
  55. t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在")
  56. activity := models.Activity{}
  57. exist, err = models.Get(&activity, entryPerson.ActivityId)
  58. t.CheckErr(err)
  59. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  60. t.CheckRunning(activity.Status)
  61. area := models.AreaStore{}
  62. exist, err = models.Get(&area, entryPerson.AreaId)
  63. t.CheckErr(err)
  64. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
  65. letter := &models.InvitationLetter{}
  66. exist, err = letter.GetByUserIdAndActivityId(userId, activity.Id, activity.ArchId, activity.RehearsalId)
  67. t.CheckErr(err)
  68. t.Assert(exist, code.MSG_INVITE_LETTER_NOT_EXIST, "邀请函不存在")
  69. items, err := invitation_service.GetOptionItem(activity.Id)
  70. t.CheckErr(err)
  71. values, err := invitation_service.GetOptionValue(items, letter.ExtraData)
  72. t.CheckErr(err)
  73. var name, phone, address = "", "", ""
  74. for _, value := range values {
  75. if v, ok := value["姓名"]; ok {
  76. name = fmt.Sprint(v)
  77. } else if v, ok := value["手机"]; ok {
  78. phone = fmt.Sprint(v)
  79. } else if v, ok := value["地址"]; ok {
  80. address = fmt.Sprint(v)
  81. }
  82. }
  83. s := core.GetXormAuto().NewSession()
  84. defer s.Close()
  85. err = s.Begin()
  86. if err != nil {
  87. s.Rollback()
  88. t.CheckErr(err)
  89. }
  90. good := models.CustomerGoods{}
  91. exist, err = s.Where("is_delete=0 and id=?", goodId).Get(&good)
  92. if err != nil || !exist {
  93. s.Rollback()
  94. t.ERROR("商品信息异常", code.MSG_ERR_Param)
  95. return
  96. }
  97. // 找出商品库存
  98. ms := make([]map[string]int, 0)
  99. err = s.Table(&models.CustomerOrderSub{}).Select("goods_id, sum(goods_num) as goods_num").
  100. Where("goods_id=?", good.Id).GroupBy("goods_id").Find(&ms)
  101. if err != nil {
  102. s.Rollback()
  103. t.CheckErr(err)
  104. }
  105. for _, m := range ms {
  106. if m["goods_id"] == int(good.Id) && m["goods_num"] >= good.Stock {
  107. s.Rollback()
  108. t.ERROR(good.Name+"商品库存不足", code.MSG_CUSTOMER_GOOD_NOT_ENOUGH)
  109. return
  110. }
  111. }
  112. order := models.CustomerOrder{}
  113. // 查询库存
  114. total, err := s.Where("is_delete=0").Count(&order) // 订单总数
  115. if err != nil {
  116. s.Rollback()
  117. t.CheckErr(err)
  118. }
  119. order.AreaId = entryPerson.AreaId
  120. order.ArchId = activity.ArchId
  121. order.AreaName = area.Name
  122. order.BuyerId = userId
  123. order.Type = 0
  124. order.ActivityId = activity.Id
  125. order.RehearsalId = activity.RehearsalId
  126. order.OrderEntryPersonId = entryPerson.Id
  127. order.OrderEntryPersonName = entryPerson.Name
  128. order.TotalAmount = good.Price
  129. order.Receiver = name
  130. order.Phone = phone
  131. order.Address = address
  132. order.GoodsName = good.Name
  133. order.GoodsId = good.Id
  134. order.GoodsNum = 1
  135. order.OutTradeNo = utils.RandomStr(32)
  136. order.OrderNo = fmt.Sprint(define.DefaultOrderNo + int(total))
  137. order.Status = 1
  138. _, err = s.InsertOne(&order)
  139. if err != nil {
  140. s.Rollback()
  141. t.CheckErr(err)
  142. }
  143. sub := models.CustomerOrderSub{}
  144. sub.GoodsId = good.Id
  145. sub.GoodName = good.Name
  146. sub.GoodPrice = good.Price
  147. sub.GoodsNum = 1
  148. sub.OrderId = order.Id
  149. _, err = models.Add(&sub) // 存入子订单
  150. if err != nil {
  151. s.Rollback()
  152. t.CheckErr(err)
  153. }
  154. gift := models.OrderGift{}
  155. exist, err = s.Where("is_delete=0 and activity_id=?", activity.Id).Get(&gift)
  156. if err != nil {
  157. s.Rollback()
  158. t.CheckErr(err)
  159. }
  160. if exist {
  161. prize := models.UserPrize{}
  162. prize.UserId = userId
  163. prize.ActivityId = activity.Id
  164. prize.RehearsalId = activity.RehearsalId
  165. prize.ActivityName = activity.Name
  166. prize.PrizeName = gift.GiftName
  167. prize.PrizeImg = gift.GiftPicUrl
  168. prize.ArchId = activity.ArchId
  169. prize.CustomerOrderId = order.Id
  170. prize.PrizeType = 3
  171. if gift.Num == 0 {
  172. _, err = s.InsertOne(&prize)
  173. if err != nil {
  174. s.Rollback()
  175. t.CheckErr(err)
  176. }
  177. } else if gift.Num > 0 {
  178. count, err := s.Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
  179. activity.Id, activity.RehearsalId, activity.ArchId).NoAutoCondition().Count(&order)
  180. if err != nil {
  181. s.Rollback()
  182. t.CheckErr(err)
  183. }
  184. if gift.Num >= int(count) { // 大于等于
  185. _, err = s.InsertOne(&prize)
  186. if err != nil {
  187. s.Rollback()
  188. t.CheckErr(err)
  189. }
  190. }
  191. }
  192. if prize.Id > 0 {
  193. order.UserPrizeId = prize.Id
  194. _, err = s.ID(order.Id).NoAutoCondition().Cols("user_prize_id").Update(order)
  195. if err != nil {
  196. s.Rollback()
  197. t.CheckErr(err)
  198. }
  199. }
  200. }
  201. err = s.Commit()
  202. if err != nil {
  203. s.Rollback()
  204. t.CheckErr(err)
  205. }
  206. t.SUCCESS("成功录入订单")
  207. }
  208. // 手动下单
  209. type ManualOrderGood struct {
  210. GoodId int `json:"good_id"`
  211. GoodNum int `json:"good_num"`
  212. }
  213. type ManualOrderParam struct {
  214. Name string `json:"name"`
  215. Phone string `json:"phone"`
  216. Goods []*ManualOrderGood `json:"goods"`
  217. }
  218. func (t *OrderEntryCtl) ManualOrder() {
  219. entryId := t.GetAccountId() // 录入人员id
  220. param := &ManualOrderParam{}
  221. t.Bind(param)
  222. param.Goods = make([]*ManualOrderGood, 0)
  223. err := json.Unmarshal([]byte(t.Request.REQUEST["goods"]), &param.Goods)
  224. t.CheckErr(err)
  225. if len(param.Goods) <= 0 {
  226. t.ERROR("商品不能为空", code.MSG_CUSTOMER_GOOD_NOT_EXIST)
  227. return
  228. }
  229. entryPerson := models.OrderEntryPerson{}
  230. exist, err := models.Get(&entryPerson, entryId)
  231. t.CheckErr(err)
  232. t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在")
  233. activity := models.Activity{}
  234. exist, err = models.Get(&activity, entryPerson.ActivityId)
  235. t.CheckErr(err)
  236. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  237. t.CheckRunning(activity.Status)
  238. area := models.AreaStore{}
  239. exist, err = models.Get(&area, entryPerson.AreaId)
  240. t.CheckErr(err)
  241. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
  242. goodIds := make([]int, 0)
  243. for _, g := range param.Goods {
  244. goodIds = append(goodIds, g.GoodId)
  245. }
  246. s := core.GetXormAuto().NewSession()
  247. defer s.Close()
  248. err = s.Begin()
  249. if err != nil {
  250. s.Rollback()
  251. t.CheckErr(err)
  252. }
  253. user := models.User{}
  254. exist, err = s.Where("is_delete=0 and phone=?", param.Phone).NoAutoCondition().Get(&user)
  255. if err != nil {
  256. s.Rollback()
  257. t.CheckErr(err)
  258. }
  259. if !exist {
  260. user.Phone = param.Phone
  261. user.Nickname = param.Name
  262. user.Password = utils.RandomStr(8)
  263. _, err = s.InsertOne(&user)
  264. if err != nil {
  265. s.Rollback()
  266. t.CheckErr(err)
  267. }
  268. }
  269. // 校验库存
  270. goods := make([]*models.CustomerGoods, 0)
  271. err = s.Where("is_delete=0").In("id", goodIds).Find(&goods)
  272. if err != nil {
  273. s.Rollback()
  274. t.CheckErr(err)
  275. }
  276. if len(goods) != len(param.Goods) {
  277. s.Rollback()
  278. t.ERROR("商品信息异常", code.MSG_ERR_Param)
  279. return
  280. }
  281. subs := make([]*models.CustomerOrderSub, 0)
  282. totalAmount := 0.00
  283. goodNum := 0
  284. for _, g := range param.Goods {
  285. for _, good := range goods {
  286. if g.GoodId == good.Id {
  287. subs = append(subs, &models.CustomerOrderSub{
  288. GoodsId: good.Id,
  289. GoodsNum: g.GoodNum,
  290. GoodName: good.Name,
  291. GoodPrice: good.Price,
  292. })
  293. totalAmount += good.Price * float64(g.GoodNum)
  294. goodNum += g.GoodNum
  295. }
  296. }
  297. }
  298. ms := make([]map[string]int, 0)
  299. err = s.Table(&models.CustomerOrderSub{}).Select("goods_id, sum(goods_num) as goods_num").
  300. In("goods_id", goodIds).GroupBy("goods_id").Find(&ms)
  301. if err != nil {
  302. s.Rollback()
  303. t.CheckErr(err)
  304. }
  305. for _, m := range ms {
  306. for _, g := range goods {
  307. if g.Stock == -1 { // 无上限
  308. break
  309. }
  310. if m["goods_id"] == int(g.Id) && m["goods_num"] >= g.Stock {
  311. s.Rollback()
  312. t.ERROR(g.Name+"商品库存不足", code.MSG_CUSTOMER_GOOD_NOT_ENOUGH)
  313. return
  314. }
  315. }
  316. }
  317. order := models.CustomerOrder{}
  318. count, err := s.Where("is_delete=0").Count(&order) // 查看订单所在
  319. if err != nil {
  320. s.Rollback()
  321. t.CheckErr(err)
  322. }
  323. order.AreaId = entryPerson.AreaId
  324. order.AreaName = area.Name
  325. order.ArchId = activity.ArchId
  326. order.BuyerId = user.Id
  327. order.Type = 0
  328. order.ActivityId = activity.Id
  329. order.RehearsalId = activity.RehearsalId
  330. order.OrderEntryPersonId = entryPerson.Id
  331. order.OrderEntryPersonName = entryPerson.Name
  332. order.TotalAmount = totalAmount
  333. order.Receiver = param.Name
  334. order.Phone = param.Phone
  335. order.GoodsNum = goodNum
  336. order.OutTradeNo = utils.RandomStr(32)
  337. order.OrderNo = fmt.Sprint(define.DefaultOrderNo + int(count))
  338. order.Status = 1
  339. _, err = s.InsertOne(&order)
  340. if err != nil {
  341. s.Rollback()
  342. t.CheckErr(err)
  343. }
  344. for _, sub := range subs {
  345. sub.OrderId = order.Id
  346. _, err = models.Add(sub) // 存入子订单
  347. if err != nil {
  348. s.Rollback()
  349. t.CheckErr(err)
  350. }
  351. }
  352. gift := models.OrderGift{}
  353. exist, err = s.Where("is_delete=0 and activity_id=?", activity.Id).Get(&gift)
  354. if err != nil {
  355. s.Rollback()
  356. t.CheckErr(err)
  357. }
  358. if exist {
  359. prize := models.UserPrize{}
  360. prize.UserId = user.Id
  361. prize.ActivityId = activity.Id
  362. prize.RehearsalId = activity.RehearsalId
  363. prize.ActivityName = activity.Name
  364. prize.PrizeName = gift.GiftName
  365. prize.PrizeImg = gift.GiftPicUrl
  366. prize.ArchId = activity.ArchId
  367. prize.CustomerOrderId = order.Id
  368. prize.PrizeType = 3
  369. if gift.Num == 0 {
  370. _, err = s.InsertOne(&prize)
  371. if err != nil {
  372. s.Rollback()
  373. t.CheckErr(err)
  374. }
  375. } else if gift.Num > 0 {
  376. count, err := s.Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
  377. activity.Id, activity.RehearsalId, activity.ArchId).NoAutoCondition().Count(&order)
  378. if err != nil {
  379. s.Rollback()
  380. t.CheckErr(err)
  381. }
  382. if gift.Num >= int(count) { // 大于等于
  383. _, err = s.InsertOne(&prize)
  384. if err != nil {
  385. s.Rollback()
  386. t.CheckErr(err)
  387. }
  388. }
  389. }
  390. if prize.Id > 0 {
  391. order.UserPrizeId = prize.Id
  392. _, err = s.ID(order.Id).NoAutoCondition().Cols("user_prize_id").Update(&order)
  393. if err != nil {
  394. s.Rollback()
  395. t.CheckErr(err)
  396. }
  397. }
  398. }
  399. err = s.Commit()
  400. if err != nil {
  401. s.Rollback()
  402. t.CheckErr(err)
  403. }
  404. t.SUCCESS("成功录入订单")
  405. }
  406. // 订单列表
  407. func (t *OrderEntryCtl) ListOrder() {
  408. }
  409. func (t *OrderEntryCtl) DeleteOrder() {
  410. orderId := t.MustGetInt("order_id")
  411. order := new(models.CustomerOrder)
  412. exist, err := models.Get(order, orderId)
  413. t.CheckErr(err)
  414. t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单不存在")
  415. _, err = models.Del(order, order.Id)
  416. t.CheckErr(err)
  417. if order.UserPrizeId > 0 {
  418. _, err = models.Del(&models.UserPrize{}, order.UserPrizeId)
  419. t.CheckErr(err)
  420. }
  421. t.SUCCESS("删除成功")
  422. }
  423. type OrderListResult struct {
  424. OrderId int `json:"order_id"`
  425. UserId int `json:"user_id"`
  426. EntryName string `json:"entry_name"`
  427. GoodName string `json:"good_name"`
  428. OrderTime string `json:"order_time"`
  429. OrderMoney float64 `json:"order_money"`
  430. Receiver string `json:"receiver"`
  431. Phone string `json:"phone"`
  432. Address string `json:"address"`
  433. Extra interface{} `json:"extra"` // 额外信息
  434. ExtraData string `json:"-"`
  435. }
  436. func (t *OrderEntryCtl) EntryOrders() {
  437. uid := t.GetAccountId()
  438. entry := models.OrderEntryPerson{}
  439. exist, err := models.Get(&entry, uid)
  440. t.CheckErr(err)
  441. t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在")
  442. activity := models.Activity{}
  443. exist, err = models.Get(&activity, entry.ActivityId)
  444. t.CheckErr(err)
  445. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  446. customer := models.Customer{}
  447. exist, err = models.Get(&customer, activity.CustomerId)
  448. t.CheckErr(err)
  449. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  450. list := make([]*OrderListResult, 0)
  451. if customer.IsSpecial == 0 {
  452. // 添加邀请函的内容
  453. err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o").
  454. Select("o.receiver as receiver, o.phone as phone, o.address as address,l.extra_data as extra_data, "+
  455. " g.name as good_name, o.buyer_id as user_id, o.total_amount as order_money, o.id as order_id, "+
  456. " DATE_FORMAT(o.created_at, '%Y-%m-%d %H:%i:%S') AS order_time").Join("LEFT",
  457. (&models.CustomerGoods{}).Alias("g"), "o.goods_id=g.id and o.activity_id=g.activity_id and g.is_delete=0").
  458. Join("LEFT", (&models.InvitationLetter{}).Alias("l"), "l.user_id = o.buyer_id and o.activity_id=l.activity_id and o.arch_id=l.arch_id and l.is_delete=0").
  459. Where("o.activity_id=? and o.order_entry_person_id=? and o.rehearsal_id=? and o.arch_id=? "+
  460. " and o.is_delete=0", activity.Id, uid, activity.RehearsalId, activity.ArchId).
  461. Desc("o.created_at").Find(&list)
  462. t.CheckErr(err)
  463. optionItems, err := invitation_service.GetOptionItem(activity.Id)
  464. t.CheckErr(err)
  465. for i := range list {
  466. data, err := invitation_service.GetOptionValue(optionItems, list[i].ExtraData)
  467. t.CheckErr(err)
  468. list[i].Extra = data
  469. list[i].EntryName = entry.Name
  470. }
  471. } else if customer.IsSpecial == 2 {
  472. err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o").Select("o.id as order_id, "+
  473. " o.receiver as receiver, o.phone as phone, o.address as address, o.buyer_id as user_id, o.order_entry_person_name as entry_name, "+
  474. " o.total_amount as order_money, DATE_FORMAT(o.created_at, '%Y-%m-%d %H:%i:%S') AS order_time").
  475. Where("o.activity_id=? and o.rehearsal_id=? and o.order_entry_person_id=? and o.arch_id=?",
  476. activity.Id, activity.RehearsalId, uid, activity.ArchId).Find(&list)
  477. t.CheckErr(err)
  478. orderIds := make([]int, 0)
  479. for _, v := range list {
  480. orderIds = append(orderIds, v.OrderId)
  481. }
  482. subs, err := models.GetCustomerOrderSubsByOrderIds(orderIds)
  483. t.CheckErr(err)
  484. for i := range list {
  485. s := make([]interface{}, 0)
  486. for _, sub := range subs {
  487. if sub["order_id"] == fmt.Sprint(list[i].OrderId) {
  488. s = append(s, sub)
  489. }
  490. }
  491. list[i].Extra = s
  492. }
  493. }
  494. t.JSON(map[string]interface{}{
  495. "list": list,
  496. "total": len(list),
  497. })
  498. }
  499. // 用户订单列表
  500. type UserOrdersResult struct {
  501. models.CustomerOrder `xorm:"extends"`
  502. Good *models.CustomerGoods `json:"good" xorm:"extends"`
  503. }
  504. // 用户查看订单列表
  505. func (t *OrderEntryCtl) UserOrders() {
  506. uid := t.GetAccountId()
  507. activityId := t.MustGetInt("activity_id")
  508. activity := new(models.Activity)
  509. exist, err := models.Get(activity, activityId)
  510. t.CheckErr(err)
  511. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  512. orders := make([]UserOrdersResult, 0)
  513. s := core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o").
  514. Join("LEFT", new(models.CustomerGoods).Alias("g"),
  515. "o.goods_id=g.id and g.is_delete=0").
  516. Where("o.buyer_id=? and o.is_delete=0 and o.activity_id=? and o.rehearsal_id=? and o.arch_id=?",
  517. uid, activity.Id, activity.RehearsalId, activity.ArchId)
  518. if t.PageSize > 0 {
  519. s = s.Limit(t.PageSize, t.Page*t.PageSize)
  520. }
  521. total, err := s.Desc("o.created_at").FindAndCount(&orders)
  522. t.CheckErr(err)
  523. t.JSON(map[string]interface{}{
  524. "list": orders,
  525. "total": total,
  526. })
  527. }
  528. // 二维码
  529. func (t *OrderEntryCtl) Qrcode() {
  530. userId := t.MustGetInt("user_id")
  531. activityId := t.MustGetInt("activity_id")
  532. goodId := t.MustGetInt("good_id")
  533. Url := fmt.Sprintf("%s/PcClient/Client/OrderEntryCtl/order?user_id=%d&activity_id=%d&good_id=%d",
  534. define.HOST, userId, activityId, goodId)
  535. qr, err := utils.Qrcode2Base64(Url)
  536. t.CheckErr(err)
  537. t.JSON(map[string]interface{}{
  538. "qrcode": qr,
  539. })
  540. }