互动
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
4 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
4 years ago
4 years ago
4 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
4 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
4 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
4 years ago
5 years ago
4 years ago
5 years ago
4 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{}).Alias("s").Select("s.goods_id, COALESCE(SUM(s.goods_num), 0) as goods_num").
  300. Join("left", (&models.CustomerOrder{}).Alias("o"), "o.id=s.order_id").
  301. Where("o.activity_id=? and o.rehearsal_id=? and o.arch_id=?", activity.Id, activity.RehearsalId, activity.ArchId).
  302. In("s.goods_id", goodIds).GroupBy("s.goods_id").Find(&ms)
  303. if err != nil {
  304. s.Rollback()
  305. t.CheckErr(err)
  306. }
  307. for _, m := range ms {
  308. for _, g := range goods {
  309. if g.Stock == -1 { // 无上限
  310. break
  311. }
  312. if m["goods_id"] == int(g.Id) && m["goods_num"] >= g.Stock {
  313. s.Rollback()
  314. t.ERROR(g.Name+"商品库存不足", code.MSG_CUSTOMER_GOOD_NOT_ENOUGH)
  315. return
  316. }
  317. }
  318. }
  319. order := models.CustomerOrder{}
  320. count, err := s.Where("is_delete=0").Count(&order) // 查看订单所在
  321. if err != nil {
  322. s.Rollback()
  323. t.CheckErr(err)
  324. }
  325. order.AreaId = entryPerson.AreaId
  326. order.AreaName = area.Name
  327. order.ArchId = activity.ArchId
  328. order.BuyerId = user.Id
  329. order.Type = 0
  330. order.ActivityId = activity.Id
  331. order.RehearsalId = activity.RehearsalId
  332. order.OrderEntryPersonId = entryPerson.Id
  333. order.OrderEntryPersonName = entryPerson.Name
  334. order.TotalAmount = totalAmount
  335. order.Receiver = param.Name
  336. order.Phone = param.Phone
  337. order.GoodsNum = goodNum
  338. order.GoodsId = subs[0].GoodsId
  339. order.GoodsName = subs[0].GoodName
  340. order.OutTradeNo = utils.RandomStr(32)
  341. order.OrderNo = fmt.Sprint(define.DefaultOrderNo + int(count))
  342. order.Status = 1
  343. _, err = s.InsertOne(&order)
  344. if err != nil {
  345. s.Rollback()
  346. t.CheckErr(err)
  347. }
  348. for _, sub := range subs {
  349. sub.OrderId = order.Id
  350. _, err = models.Add(sub) // 存入子订单
  351. if err != nil {
  352. s.Rollback()
  353. t.CheckErr(err)
  354. }
  355. }
  356. gift := models.OrderGift{}
  357. exist, err = s.Where("is_delete=0 and activity_id=?", activity.Id).Get(&gift)
  358. if err != nil {
  359. s.Rollback()
  360. t.CheckErr(err)
  361. }
  362. if exist {
  363. prize := models.UserPrize{}
  364. prize.UserId = user.Id
  365. prize.ActivityId = activity.Id
  366. prize.RehearsalId = activity.RehearsalId
  367. prize.ActivityName = activity.Name
  368. prize.PrizeName = gift.GiftName
  369. prize.PrizeImg = gift.GiftPicUrl
  370. prize.ArchId = activity.ArchId
  371. prize.CustomerOrderId = order.Id
  372. prize.PrizeType = 3
  373. if gift.Num == 0 {
  374. _, err = s.InsertOne(&prize)
  375. if err != nil {
  376. s.Rollback()
  377. t.CheckErr(err)
  378. }
  379. } else if gift.Num > 0 {
  380. count, err := s.Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
  381. activity.Id, activity.RehearsalId, activity.ArchId).NoAutoCondition().Count(&order)
  382. if err != nil {
  383. s.Rollback()
  384. t.CheckErr(err)
  385. }
  386. if gift.Num >= int(count) { // 大于等于
  387. _, err = s.InsertOne(&prize)
  388. if err != nil {
  389. s.Rollback()
  390. t.CheckErr(err)
  391. }
  392. }
  393. }
  394. if prize.Id > 0 {
  395. order.UserPrizeId = prize.Id
  396. _, err = s.ID(order.Id).NoAutoCondition().Cols("user_prize_id").Update(&order)
  397. if err != nil {
  398. s.Rollback()
  399. t.CheckErr(err)
  400. }
  401. }
  402. }
  403. err = s.Commit()
  404. if err != nil {
  405. s.Rollback()
  406. t.CheckErr(err)
  407. }
  408. t.SUCCESS("成功录入订单")
  409. }
  410. func (t *OrderEntryCtl) DeleteOrder() {
  411. orderId := t.MustGetInt("order_id")
  412. order := new(models.CustomerOrder)
  413. exist, err := models.Get(order, orderId)
  414. t.CheckErr(err)
  415. t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单不存在")
  416. _, err = models.Del(order, order.Id)
  417. t.CheckErr(err)
  418. if order.UserPrizeId > 0 {
  419. _, err = models.Del(&models.UserPrize{}, order.UserPrizeId)
  420. t.CheckErr(err)
  421. }
  422. t.SUCCESS("删除成功")
  423. }
  424. type OrderListResult struct {
  425. OrderId int `json:"order_id"`
  426. UserId int `json:"user_id"`
  427. EntryName string `json:"entry_name"`
  428. GoodName string `json:"-"`
  429. OrderTime string `json:"order_time"`
  430. OrderMoney float64 `json:"order_money"`
  431. Receiver string `json:"receiver"`
  432. Phone string `json:"phone"`
  433. Address string `json:"address"`
  434. Extra interface{} `json:"extra"` // 额外信息
  435. ExtraData string `json:"-"`
  436. }
  437. func (t *OrderEntryCtl) EntryOrders() {
  438. uid := t.GetAccountId()
  439. entry := models.OrderEntryPerson{}
  440. exist, err := models.Get(&entry, uid)
  441. t.CheckErr(err)
  442. t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在")
  443. activity := models.Activity{}
  444. exist, err = models.Get(&activity, entry.ActivityId)
  445. t.CheckErr(err)
  446. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  447. customer := models.Customer{}
  448. exist, err = models.Get(&customer, activity.CustomerId)
  449. t.CheckErr(err)
  450. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  451. list := make([]*OrderListResult, 0)
  452. //if customer.IsSpecial == 0 {
  453. // // 添加邀请函的内容
  454. // err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o").
  455. // Select("o.receiver as receiver, o.phone as phone, o.address as address,l.extra_data as extra_data, "+
  456. // " g.name as good_name, o.buyer_id as user_id, o.total_amount as order_money, o.id as order_id, "+
  457. // " DATE_FORMAT(o.created_at, '%Y-%m-%d %H:%i:%S') AS order_time").Join("LEFT",
  458. // (&models.CustomerGoods{}).Alias("g"), "o.goods_id=g.id and o.activity_id=g.activity_id").
  459. // 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").
  460. // Where("o.activity_id=? and o.order_entry_person_id=? and o.rehearsal_id=? and o.arch_id=? "+
  461. // " and o.is_delete=0", activity.Id, uid, activity.RehearsalId, activity.ArchId).
  462. // Desc("o.created_at").Find(&list)
  463. // t.CheckErr(err)
  464. // optionItems, err := invitation_service.GetOptionItem(activity.Id)
  465. // t.CheckErr(err)
  466. // for i := range list {
  467. // data, err := invitation_service.GetOptionValue(optionItems, list[i].ExtraData)
  468. // t.CheckErr(err)
  469. // list[i].Extra = data
  470. // list[i].EntryName = entry.Name
  471. // }
  472. //} else if customer.IsSpecial == 2 {
  473. err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o").Select("o.id as order_id, "+
  474. " 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, "+
  475. " o.total_amount as order_money, DATE_FORMAT(o.created_at, '%Y-%m-%d %H:%i:%S') AS order_time").
  476. Where("o.activity_id=? and o.rehearsal_id=? and o.order_entry_person_id=? and o.arch_id=?",
  477. activity.Id, activity.RehearsalId, uid, activity.ArchId).Desc("o.created_at").Find(&list)
  478. t.CheckErr(err)
  479. orderIds := make([]int, 0)
  480. for _, v := range list {
  481. orderIds = append(orderIds, v.OrderId)
  482. }
  483. subs, err := models.GetCustomerOrderSubsByOrderIds(orderIds)
  484. t.CheckErr(err)
  485. for i := range list {
  486. s := make([]interface{}, 0)
  487. for _, sub := range subs {
  488. if sub["order_id"] == fmt.Sprint(list[i].OrderId) {
  489. s = append(s, sub)
  490. }
  491. }
  492. list[i].Extra = s
  493. }
  494. //}
  495. t.JSON(map[string]interface{}{
  496. "list": list,
  497. "total": len(list),
  498. })
  499. }
  500. // 用户订单列表
  501. type UserOrdersResult struct {
  502. models.CustomerOrder `xorm:"extends"`
  503. Good *models.CustomerGoods `json:"good" xorm:"extends"`
  504. }
  505. // 用户查看订单列表
  506. func (t *OrderEntryCtl) UserOrders() {
  507. uid := t.GetAccountId()
  508. activityId := t.MustGetInt("activity_id")
  509. activity := new(models.Activity)
  510. exist, err := models.Get(activity, activityId)
  511. t.CheckErr(err)
  512. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  513. orders := make([]UserOrdersResult, 0)
  514. s := core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o").
  515. Join("LEFT", new(models.CustomerGoods).Alias("g"),
  516. "o.goods_id=g.id and g.is_delete=0").
  517. Where("o.buyer_id=? and o.is_delete=0 and o.activity_id=? and o.rehearsal_id=? and o.arch_id=?",
  518. uid, activity.Id, activity.RehearsalId, activity.ArchId)
  519. if t.PageSize > 0 {
  520. s = s.Limit(t.PageSize, t.Page*t.PageSize)
  521. }
  522. total, err := s.Desc("o.created_at").FindAndCount(&orders)
  523. t.CheckErr(err)
  524. t.JSON(map[string]interface{}{
  525. "list": orders,
  526. "total": total,
  527. })
  528. }
  529. // 二维码
  530. func (t *OrderEntryCtl) Qrcode() {
  531. userId := t.MustGetInt("user_id")
  532. activityId := t.MustGetInt("activity_id")
  533. goodId := t.MustGetInt("good_id")
  534. Url := fmt.Sprintf("%s/PcClient/Client/OrderEntryCtl/order?user_id=%d&activity_id=%d&good_id=%d",
  535. define.HOST, userId, activityId, goodId)
  536. qr, err := utils.Qrcode2Base64(Url)
  537. t.CheckErr(err)
  538. t.JSON(map[string]interface{}{
  539. "qrcode": qr,
  540. })
  541. }