互动
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.

584 lines
16 KiB

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
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
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
4 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. "hudongzhuanjia/utils"
  8. "hudongzhuanjia/utils/code"
  9. "hudongzhuanjia/utils/define"
  10. "strings"
  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_USER {
  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. values := make([]map[string]interface{}, 0)
  70. err = json.Unmarshal([]byte(strings.Trim(letter.ExtraData, `"`)), &values)
  71. t.CheckErr(err)
  72. var name, phone, address = "", "", ""
  73. for _, value := range values {
  74. if value["name"] == "姓名" {
  75. name = fmt.Sprint(value["val"])
  76. } else if value["name"] == "手机" {
  77. phone = fmt.Sprint(value["val"])
  78. } else if value["name"] == "地址" {
  79. address = fmt.Sprint(value["val"])
  80. }
  81. }
  82. s := core.GetXormAuto().NewSession()
  83. defer s.Close()
  84. err = s.Begin()
  85. if err != nil {
  86. s.Rollback()
  87. t.CheckErr(err)
  88. }
  89. good := models.CustomerGoods{}
  90. exist, err = s.Where("is_delete=0 and id=?", goodId).Get(&good)
  91. if err != nil || !exist {
  92. s.Rollback()
  93. t.ERROR("商品信息异常", code.MSG_ERR_Param)
  94. return
  95. }
  96. // 找出商品库存
  97. ms := make([]map[string]int, 0)
  98. err = s.Table(&models.CustomerOrderSub{}).Select("goods_id, sum(goods_num) as goods_num").
  99. Where("goods_id=?", good.Id).GroupBy("goods_id").Find(&ms)
  100. if err != nil {
  101. s.Rollback()
  102. t.CheckErr(err)
  103. }
  104. for _, m := range ms {
  105. if m["goods_id"] == int(good.Id) && m["goods_num"] >= good.Stock {
  106. s.Rollback()
  107. t.ERROR(good.Name+"商品库存不足", code.MSG_CUSTOMER_GOOD_NOT_ENOUGH)
  108. return
  109. }
  110. }
  111. order := models.CustomerOrder{}
  112. // 查询库存
  113. total, err := s.Where("is_delete=0").Count(&order) // 订单总数
  114. if err != nil {
  115. s.Rollback()
  116. t.CheckErr(err)
  117. }
  118. order.AreaId = entryPerson.AreaId
  119. order.ArchId = activity.ArchId
  120. order.AreaName = area.Name
  121. order.BuyerId = userId
  122. order.Type = 0
  123. order.ActivityId = activity.Id
  124. order.RehearsalId = activity.RehearsalId
  125. order.OrderEntryPersonId = entryPerson.Id
  126. order.OrderEntryPersonName = entryPerson.Name
  127. order.TotalAmount = good.Price
  128. order.Receiver = name
  129. order.Phone = phone
  130. order.Address = address
  131. order.GoodsName = good.Name
  132. order.GoodsId = good.Id
  133. order.GoodsNum = 1
  134. order.OutTradeNo = utils.RandomStr(32)
  135. order.OrderNo = fmt.Sprint(define.DefaultOrderNo + int(total))
  136. order.Status = 1
  137. _, err = s.InsertOne(&order)
  138. if err != nil {
  139. s.Rollback()
  140. t.CheckErr(err)
  141. }
  142. sub := models.CustomerOrderSub{}
  143. sub.GoodsId = good.Id
  144. sub.GoodName = good.Name
  145. sub.GoodPrice = good.Price
  146. sub.GoodsNum = 1
  147. sub.OrderId = order.Id
  148. _, err = models.Add(&sub) // 存入子订单
  149. if err != nil {
  150. s.Rollback()
  151. t.CheckErr(err)
  152. }
  153. gift := models.OrderGift{}
  154. exist, err = s.Where("is_delete=0 and activity_id=?", activity.Id).Get(&gift)
  155. if err != nil {
  156. s.Rollback()
  157. t.CheckErr(err)
  158. }
  159. if exist {
  160. prize := models.UserPrize{}
  161. prize.UserId = userId
  162. prize.ActivityId = activity.Id
  163. prize.RehearsalId = activity.RehearsalId
  164. prize.ActivityName = activity.Name
  165. prize.PrizeName = gift.GiftName
  166. prize.PrizeImg = gift.GiftPicUrl
  167. prize.ArchId = activity.ArchId
  168. prize.CustomerOrderId = order.Id
  169. prize.PrizeType = 3
  170. if gift.Num == 0 {
  171. _, err = s.InsertOne(&prize)
  172. if err != nil {
  173. s.Rollback()
  174. t.CheckErr(err)
  175. }
  176. } else if gift.Num > 0 {
  177. count, err := s.Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
  178. activity.Id, activity.RehearsalId, activity.ArchId).NoAutoCondition().Count(&order)
  179. if err != nil {
  180. s.Rollback()
  181. t.CheckErr(err)
  182. }
  183. if gift.Num >= int(count) { // 大于等于
  184. _, err = s.InsertOne(&prize)
  185. if err != nil {
  186. s.Rollback()
  187. t.CheckErr(err)
  188. }
  189. }
  190. }
  191. if prize.Id > 0 {
  192. order.UserPrizeId = prize.Id
  193. _, err = s.ID(order.Id).NoAutoCondition().Cols("user_prize_id").Update(&order)
  194. if err != nil {
  195. s.Rollback()
  196. t.CheckErr(err)
  197. }
  198. }
  199. }
  200. err = s.Commit()
  201. if err != nil {
  202. s.Rollback()
  203. t.CheckErr(err)
  204. }
  205. t.SUCCESS("成功录入订单")
  206. }
  207. // 手动下单
  208. type ManualOrderGood struct {
  209. GoodId int `json:"good_id"`
  210. GoodNum int `json:"good_num"`
  211. }
  212. type ManualOrderParam struct {
  213. Name string `json:"name"`
  214. Phone string `json:"phone"`
  215. Goods []*ManualOrderGood `json:"goods"`
  216. }
  217. func (t *OrderEntryCtl) ManualOrder() {
  218. entryId := t.GetAccountId() // 录入人员id
  219. param := &ManualOrderParam{}
  220. t.Bind(param)
  221. param.Goods = make([]*ManualOrderGood, 0)
  222. err := json.Unmarshal([]byte(t.Request.REQUEST["goods"]), &param.Goods)
  223. t.CheckErr(err)
  224. if len(param.Goods) <= 0 {
  225. t.ERROR("商品不能为空", code.MSG_CUSTOMER_GOOD_NOT_EXIST)
  226. return
  227. }
  228. entryPerson := models.OrderEntryPerson{}
  229. exist, err := models.Get(&entryPerson, entryId)
  230. t.CheckErr(err)
  231. t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在")
  232. activity := models.Activity{}
  233. exist, err = models.Get(&activity, entryPerson.ActivityId)
  234. t.CheckErr(err)
  235. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  236. t.CheckRunning(activity.Status)
  237. area := models.AreaStore{}
  238. exist, err = models.Get(&area, entryPerson.AreaId)
  239. t.CheckErr(err)
  240. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
  241. goodIds := make([]int, 0)
  242. for _, g := range param.Goods {
  243. goodIds = append(goodIds, g.GoodId)
  244. }
  245. s := core.GetXormAuto().NewSession()
  246. defer s.Close()
  247. err = s.Begin()
  248. if err != nil {
  249. s.Rollback()
  250. t.CheckErr(err)
  251. }
  252. user := models.User{}
  253. exist, err = s.Where("is_delete=0 and phone=?", param.Phone).NoAutoCondition().Get(&user)
  254. if err != nil {
  255. s.Rollback()
  256. t.CheckErr(err)
  257. }
  258. if !exist {
  259. user.Phone = param.Phone
  260. user.Nickname = param.Name
  261. user.Password = utils.RandomStr(8)
  262. _, err = s.InsertOne(&user)
  263. if err != nil {
  264. s.Rollback()
  265. t.CheckErr(err)
  266. }
  267. }
  268. // 校验库存
  269. goods := make([]*models.CustomerGoods, 0)
  270. err = s.Where("is_delete=0").In("id", goodIds).Find(&goods)
  271. if err != nil {
  272. s.Rollback()
  273. t.CheckErr(err)
  274. }
  275. if len(goods) != len(param.Goods) {
  276. s.Rollback()
  277. t.ERROR("商品信息异常", code.MSG_ERR_Param)
  278. return
  279. }
  280. subs := make([]*models.CustomerOrderSub, 0)
  281. totalAmount := 0.00
  282. goodNum := 0
  283. for _, g := range param.Goods {
  284. for _, good := range goods {
  285. if g.GoodId == good.Id {
  286. subs = append(subs, &models.CustomerOrderSub{
  287. GoodsId: good.Id,
  288. GoodsNum: g.GoodNum,
  289. GoodName: good.Name,
  290. GoodPrice: good.Price,
  291. })
  292. totalAmount += good.Price * float64(g.GoodNum)
  293. goodNum += g.GoodNum
  294. }
  295. }
  296. }
  297. ms := make([]map[string]int, 0)
  298. err = s.Table(&models.CustomerOrderSub{}).Alias("s").Select("s.goods_id, COALESCE(SUM(s.goods_num), 0) as goods_num").
  299. Join("left", (&models.CustomerOrder{}).Alias("o"), "o.id=s.order_id").
  300. Where("o.activity_id=? and o.rehearsal_id=? and o.arch_id=?", activity.Id, activity.RehearsalId, activity.ArchId).
  301. In("s.goods_id", goodIds).GroupBy("s.goods_id").Find(&ms)
  302. if err != nil {
  303. s.Rollback()
  304. t.CheckErr(err)
  305. }
  306. for _, m := range ms {
  307. for _, g := range goods {
  308. if g.Stock == -1 { // 无上限
  309. break
  310. }
  311. if m["goods_id"] == int(g.Id) && m["goods_num"] >= g.Stock {
  312. s.Rollback()
  313. t.ERROR(g.Name+"商品库存不足", code.MSG_CUSTOMER_GOOD_NOT_ENOUGH)
  314. return
  315. }
  316. }
  317. }
  318. order := models.CustomerOrder{}
  319. count, err := s.Where("is_delete=0").Count(&order) // 查看订单所在
  320. if err != nil {
  321. s.Rollback()
  322. t.CheckErr(err)
  323. }
  324. order.AreaId = entryPerson.AreaId
  325. order.AreaName = area.Name
  326. order.ArchId = activity.ArchId
  327. order.BuyerId = user.Id
  328. order.Type = 0
  329. order.ActivityId = activity.Id
  330. order.RehearsalId = activity.RehearsalId
  331. order.OrderEntryPersonId = entryPerson.Id
  332. order.OrderEntryPersonName = entryPerson.Name
  333. order.TotalAmount = totalAmount
  334. order.Receiver = param.Name
  335. order.Phone = param.Phone
  336. order.GoodsNum = goodNum
  337. order.GoodsId = subs[0].GoodsId
  338. order.GoodsName = subs[0].GoodName
  339. order.OutTradeNo = utils.RandomStr(32)
  340. order.OrderNo = fmt.Sprint(define.DefaultOrderNo + int(count))
  341. order.Status = 1
  342. _, err = s.InsertOne(&order)
  343. if err != nil {
  344. s.Rollback()
  345. t.CheckErr(err)
  346. }
  347. for _, sub := range subs {
  348. sub.OrderId = order.Id
  349. _, err = models.Add(sub) // 存入子订单
  350. if err != nil {
  351. s.Rollback()
  352. t.CheckErr(err)
  353. }
  354. }
  355. gift := models.OrderGift{}
  356. exist, err = s.Where("is_delete=0 and activity_id=?", activity.Id).Get(&gift)
  357. if err != nil {
  358. s.Rollback()
  359. t.CheckErr(err)
  360. }
  361. if exist {
  362. prize := models.UserPrize{}
  363. prize.UserId = user.Id
  364. prize.ActivityId = activity.Id
  365. prize.RehearsalId = activity.RehearsalId
  366. prize.ActivityName = activity.Name
  367. prize.PrizeName = gift.GiftName
  368. prize.PrizeImg = gift.GiftPicUrl
  369. prize.ArchId = activity.ArchId
  370. prize.CustomerOrderId = order.Id
  371. prize.PrizeType = 3
  372. if gift.Num == 0 {
  373. _, err = s.InsertOne(&prize)
  374. if err != nil {
  375. s.Rollback()
  376. t.CheckErr(err)
  377. }
  378. } else if gift.Num > 0 {
  379. count, err := s.Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
  380. activity.Id, activity.RehearsalId, activity.ArchId).NoAutoCondition().Count(&order)
  381. if err != nil {
  382. s.Rollback()
  383. t.CheckErr(err)
  384. }
  385. if gift.Num >= int(count) { // 大于等于
  386. _, err = s.InsertOne(&prize)
  387. if err != nil {
  388. s.Rollback()
  389. t.CheckErr(err)
  390. }
  391. }
  392. }
  393. if prize.Id > 0 {
  394. order.UserPrizeId = prize.Id
  395. _, err = s.ID(order.Id).NoAutoCondition().Cols("user_prize_id").Update(&order)
  396. if err != nil {
  397. s.Rollback()
  398. t.CheckErr(err)
  399. }
  400. }
  401. }
  402. err = s.Commit()
  403. if err != nil {
  404. s.Rollback()
  405. t.CheckErr(err)
  406. }
  407. t.SUCCESS("成功录入订单")
  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:"-"`
  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").
  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).Desc("o.created_at").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.OrderId == 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. }