Activity.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\controller;
  12. use app\wap\model\activity\EventRegistration;
  13. use app\wap\model\activity\EventSignUp;
  14. use app\wap\model\activity\EventData;
  15. use app\wap\model\activity\EventPrice;
  16. use service\JsonService;
  17. use service\SystemConfigService;
  18. use think\Url;
  19. /**
  20. * 活动控制器
  21. * Class Activity
  22. */
  23. class Activity extends AuthController
  24. {
  25. /**
  26. * 白名单
  27. */
  28. public static function WhiteList()
  29. {
  30. return [
  31. 'index',
  32. 'activityList'
  33. ];
  34. }
  35. /**活动列表
  36. * @return mixed
  37. */
  38. public function index()
  39. {
  40. return $this->fetch('activity_list');
  41. }
  42. /**
  43. * 获取活动列表
  44. */
  45. public function activityList($page = 1, $limit = 20)
  46. {
  47. $list = EventRegistration::eventRegistrationList($page, $limit);
  48. return JsonService::successful($list);
  49. }
  50. /**获取活动需要填写的资料
  51. * @param $id
  52. */
  53. public function getActivityEventData($id)
  54. {
  55. $event = EventData::eventDataList($id);
  56. return JsonService::successful($event);
  57. }
  58. /**获取活动的价格
  59. * @param $id
  60. */
  61. public function getActivityEventPrice($id)
  62. {
  63. $price = EventPrice::eventPriceList($id);
  64. if (!count($price)) {
  65. $activity = EventRegistration::where('id', $id)->field('price,member_price')->find();
  66. $price[0] = [
  67. 'event_id' => $id,
  68. 'event_number' => 1,
  69. 'event_price' => $activity['price'],
  70. 'event_mer_price' => $activity['member_price'],
  71. 'sort' => 0
  72. ];
  73. }
  74. return JsonService::successful($price);
  75. }
  76. /**
  77. * 核销码 搜索
  78. */
  79. public function getWriteOffCode($code = '')
  80. {
  81. if (!$code) return JsonService::fail('参数有误');
  82. if (!$this->userInfo['is_write_off']) return JsonService::fail('您没有权限核销!');
  83. $order = EventSignUp::setWhere()->where('code', $code)->find();
  84. if (!$order) return JsonService::fail('订单不存在');
  85. return JsonService::successful($order);
  86. }
  87. /**核销员 核销活动订单
  88. * @param string $order_id
  89. * @throws \think\db\exception\DataNotFoundException
  90. * @throws \think\db\exception\ModelNotFoundException
  91. * @throws \think\exception\DbException
  92. */
  93. public function scanCodeSignIn($order_id = '')
  94. {
  95. if (!$order_id) return JsonService::fail('参数有误');
  96. if (!$this->userInfo['is_write_off']) return JsonService::fail('没有权限核销!');
  97. $order = EventSignUp::setWhere()->where('order_id', $order_id)->find();
  98. if (!$order) return JsonService::fail('订单不存在');
  99. if ($order['status']) return JsonService::fail('该订单已核销');
  100. $res = EventSignUp::setWhere()->where('order_id', $order_id)->update(['status' => 1]);
  101. if ($res) return JsonService::successful('核销成功');
  102. else return JsonService::fail('核销失败');
  103. }
  104. /**获取核销订单详情
  105. * @param string $order_id
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. * @throws \think\exception\DbException
  109. */
  110. public function writeOffSignIn($order_id = '')
  111. {
  112. if (!$order_id) return JsonService::fail('参数有误');
  113. if (!$this->userInfo['is_write_off']) return JsonService::fail('没有权限核销!');
  114. $order = EventSignUp::setWhere()->where(['order_id' => $order_id])->find();
  115. if (!$order) return JsonService::fail('订单不存在');
  116. if (!$order['activity_id']) return JsonService::fail('订单有误');
  117. $activity = EventRegistration::oneActivitys($order['activity_id']);
  118. if (!$activity) return JsonService::fail('活动不存在');
  119. $order['activity'] = $activity;
  120. $order['pay_time'] = date('y/m/d H:i', $order['pay_time']);
  121. return JsonService::successful($order);
  122. }
  123. /**
  124. * 用户报名活动列表
  125. */
  126. public function activitySignInList($page = 1, $limit = 20, $navActive = 0)
  127. {
  128. $model = EventSignUp::setWhere('s')->where('s.uid', $this->uid)->page((int)$page, (int)$limit);
  129. switch ($navActive) {
  130. case 1:
  131. $model = $model->where('s.status', 0);
  132. break;
  133. case 2:
  134. $model = $model->where('s.status', 1);
  135. break;
  136. }
  137. $model = $model->join('EventRegistration r', 'r.id = s.activity_id');
  138. $orderList = $model->order('s.add_time DESC')->field('s.order_id,s.status,s.pay_price,s.activity_id,s.user_info,s.uid,s.code,s.number as upUnmber,r.title,r.image,r.province,r.city,r.statu,r.district,r.detail')->select();
  139. $orderList = count($orderList) > 0 ? $orderList->toArray() : [];
  140. return JsonService::successful($orderList);
  141. }
  142. /**活动订单详情
  143. * @param string $order_id
  144. * @throws \think\db\exception\DataNotFoundException
  145. * @throws \think\db\exception\ModelNotFoundException
  146. * @throws \think\exception\DbException
  147. */
  148. public function activitySignIn($order_id = '')
  149. {
  150. if (!$order_id) return JsonService::fail('参数有误');
  151. $order = EventSignUp::setWhere()->where(['order_id' => $order_id, 'uid' => $this->uid])->find();
  152. if (!$order) return JsonService::fail('订单不存在');
  153. if (!$order['activity_id']) return JsonService::fail('订单有误');
  154. $activity = EventRegistration::where('id', $order['activity_id'])->field('id,title,image,province,city,statu,district,detail,start_time,end_time,signup_start_time,signup_end_time,price')->find();
  155. if (!$activity) return JsonService::fail('活动不存在');
  156. $activity = EventRegistration::singleActivity($activity);
  157. $start_time = date('y/m/d H:i', $activity['start_time']);
  158. $end_time = date('y/m/d H:i', $activity['end_time']);
  159. $activity['time'] = $start_time . '~' . $end_time;
  160. $order['activity'] = $activity;
  161. $order['pay_time'] = date('y/m/d H:i', $order['pay_time']);
  162. if (!$order['write_off_code']) {
  163. $write_off_code = EventSignUp::qrcodes_url($order_id, 5);
  164. EventSignUp::where('order_id', $order_id)->update(['write_off_code' => $write_off_code]);
  165. $order['write_off_code'] = $write_off_code;
  166. }
  167. if (!$order['code']) {
  168. $code = EventSignUp::codes();
  169. EventSignUp::where('order_id', $order_id)->update(['code' => $code]);
  170. $order['code'] = $code;
  171. }
  172. return JsonService::successful($order);
  173. }
  174. /**检测活动状态
  175. * @param string $order_id
  176. */
  177. public function orderStatus($order_id = '')
  178. {
  179. if (!$order_id) return JsonService::fail('参数有误');
  180. $order = EventSignUp::setWhere()->where('order_id', $order_id)->find();
  181. if (!$order) return JsonService::fail('订单不存在');
  182. return JsonService::successful($order['status']);
  183. }
  184. }