DefaultController.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. namespace addons\SecondaryCard\api\modules\v1\controllers;
  3. use addons\SecondaryCard\common\service\SecondaryCardOrderService;
  4. use addons\SecondaryCard\common\service\SecondaryCardRedemptionCodeService;
  5. use addons\SecondaryCard\common\service\SecondaryCardService;
  6. use addons\SecondaryCard\common\service\SecondaryCardUseLogService;
  7. use common\enums\ApiStatusEnum;
  8. use Yii;
  9. use api\controllers\OnAuthController;
  10. /**
  11. * 默认控制器
  12. *
  13. * Class DefaultController
  14. * @package addons\SecondaryCard\api\modules\v1\controllers
  15. */
  16. class DefaultController extends OnAuthController
  17. {
  18. public $modelClass = '';
  19. /**
  20. * 不用进行登录验证的方法
  21. *
  22. * 例如: ['index', 'update', 'create', 'view', 'delete']
  23. * 默认全部需要验证
  24. *
  25. * @var array
  26. */
  27. protected $authOptional = ['index'];
  28. /**
  29. * 次卡列表
  30. * @Author:hua
  31. * @Date:2024-03-05 16:33
  32. * @Copyright:copyright(c)2024 广东七件事集团
  33. * @return mixed|void
  34. */
  35. public function actionSecondaryCardList()
  36. {
  37. try {
  38. $params = \Yii::$app->request->get();
  39. $params['mall_id'] = $this->mall_id;
  40. $data = SecondaryCardService::getListByH5($params);
  41. return $this->success('操作成功', $data);
  42. } catch (\Exception $e) {
  43. return $this->error($e->getMessage());
  44. }
  45. }
  46. /**
  47. * 次卡详情
  48. * @Author:hua
  49. * @Date:2024-03-05 16:33
  50. * @Copyright:copyright(c)2024 广东七件事集团
  51. * @return mixed|void
  52. */
  53. public function actionSecondaryCardDetail()
  54. {
  55. try {
  56. $params = \Yii::$app->request->get();
  57. $res = Yii::$app->services->validate->validate($params, [
  58. [['id', 'latitude', 'longitude'], 'required'],
  59. ]);
  60. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  61. $params['mall_id'] = $this->mall_id;
  62. $data = SecondaryCardService::getDetailByH5($params);
  63. return $this->success('操作成功', $data);
  64. } catch (\Exception $e) {
  65. return $this->error($e->getMessage());
  66. }
  67. }
  68. /**
  69. * 适用店铺列表
  70. * @Author:hua
  71. * @Date:2024-03-05 16:34
  72. * @Copyright:copyright(c)2024 广东七件事集团
  73. * @return mixed|void
  74. */
  75. public function actionStoreList()
  76. {
  77. try {
  78. $params = \Yii::$app->request->get();
  79. $params['mall_id'] = $this->mall_id;
  80. $data = SecondaryCardService::getStoreListByH5($params);
  81. return $this->success('操作成功', $data);
  82. } catch (\Exception $e) {
  83. return $this->error($e->getMessage());
  84. }
  85. }
  86. /**
  87. * 生成次卡订单
  88. * @Author:hua
  89. * @Date:2024-03-05 16:34
  90. * @Copyright:copyright(c)2024 广东七件事集团
  91. * @return mixed|void
  92. */
  93. public function actionCreateOrder()
  94. {
  95. try {
  96. $params = \Yii::$app->request->post();
  97. $res = Yii::$app->services->validate->validate($params, [
  98. [['secondary_card_id'], 'required'],
  99. ]);
  100. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  101. $params['mall_id'] = $this->mall_id;
  102. $params['user_id'] = $this->user_id;
  103. $res = SecondaryCardOrderService::createOrder($params);
  104. return $this->success('操作成功', $res);
  105. } catch (\Exception $e) {
  106. return $this->error($e->getMessage());
  107. }
  108. }
  109. /**
  110. * 我的次卡列表
  111. * @Author:hua
  112. * @Date:2024-03-05 16:53
  113. * @Copyright:copyright(c)2024 广东七件事集团
  114. * @return mixed|void
  115. */
  116. public function actionMySecondaryCard()
  117. {
  118. try {
  119. $params = \Yii::$app->request->get();
  120. $res = Yii::$app->services->validate->validate($params, [
  121. [['order_status'], 'safe'],
  122. ]);
  123. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  124. $params['mall_id'] = $this->mall_id;
  125. $params['user_id'] = $this->user_id;
  126. $res = SecondaryCardOrderService::getMySecondaryCard($params);
  127. return $this->success('操作成功', $res, ApiStatusEnum::CODE_SUCCESS, 0);
  128. } catch (\Exception $e) {
  129. return $this->error($e->getMessage());
  130. }
  131. }
  132. /**
  133. * 我的次卡详情
  134. * @Author:hua
  135. * @Date:2024-03-05 16:54
  136. * @Copyright:copyright(c)2024 广东七件事集团
  137. * @return mixed|void
  138. */
  139. public function actionMySecondaryCardDetail()
  140. {
  141. try {
  142. $params = \Yii::$app->request->get();
  143. $res = Yii::$app->services->validate->validate($params, [
  144. [['id', 'latitude', 'longitude'], 'required'],
  145. ]);
  146. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  147. $params['mall_id'] = $this->mall_id;
  148. $params['user_id'] = $this->user_id;
  149. $data = SecondaryCardOrderService::getMySecondaryCardDetailByH5($params);
  150. return $this->success('操作成功', $data, ApiStatusEnum::CODE_SUCCESS, 0);
  151. } catch (\Exception $e) {
  152. return $this->error($e->getMessage());
  153. }
  154. }
  155. /**
  156. * 兑换次卡
  157. * @Author:hua
  158. * @Date:2024-03-05 16:54
  159. * @Copyright:copyright(c)2024 广东七件事集团
  160. * @return mixed|void
  161. */
  162. public function actionExchangeCode()
  163. {
  164. try {
  165. $params = \Yii::$app->request->post();
  166. $res = Yii::$app->services->validate->validate($params, [
  167. [['code'], 'required'],
  168. [['secondary_card_id'], 'safe'],
  169. ]);
  170. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  171. $params['mall_id'] = $this->mall_id;
  172. $params['user_id'] = $this->user_id;
  173. $data = SecondaryCardRedemptionCodeService::ExchangeCode($params);
  174. return $this->success('操作成功', $data);
  175. } catch (\Exception $e) {
  176. return $this->error($e->getMessage());
  177. }
  178. }
  179. public function actionMySecondaryCardCounts()
  180. {
  181. try {
  182. $params = \Yii::$app->request->post();
  183. $res = Yii::$app->services->validate->validate($params, [
  184. [['secondary_card_id'], 'required'],
  185. ]);
  186. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  187. $count = SecondaryCardOrderService::getMySecondaryCardCounts($this->mall_id, $this->user_id, $params['secondary_card_id']);
  188. return $this->success('操作成功', ['counts' => $count]);
  189. } catch (\Exception $e) {
  190. return $this->error($e->getMessage());
  191. }
  192. }
  193. /**
  194. * 取消预约
  195. * @Author:hua
  196. * @Date:2024-03-08 11:07
  197. * @Copyright:copyright(c)2024 广东七件事集团
  198. * @return mixed|void
  199. */
  200. public function actionCancelReservation()
  201. {
  202. try {
  203. $params = \Yii::$app->request->post();
  204. $res = Yii::$app->services->validate->validate($params, [
  205. [['reservation_service_order_id','main_order_id'], 'safe'],
  206. ]);
  207. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  208. $params['mall_id'] = $this->mall_id;
  209. $params['user_id'] = $this->user_id;
  210. $res = SecondaryCardOrderService::cancelReservation($params);
  211. if (is_string($res)) return $this->error($res);
  212. return $this->success();
  213. } catch (\Exception $e) {
  214. return $this->error($e->getMessage());
  215. }
  216. }
  217. /**
  218. * 申请退款
  219. * @Author:hua
  220. * @Date:2024-03-08 11:07
  221. * @Copyright:copyright(c)2024 广东七件事集团
  222. * @return mixed|void
  223. */
  224. public function actionApplyRefund()
  225. {
  226. if (\Yii::$app->request->isPost) {
  227. try {
  228. $params = \Yii::$app->request->post();
  229. $res = Yii::$app->services->validate->validate($params, [
  230. [['id'], 'required'],
  231. ]);
  232. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  233. $params['user_id'] = $this->user_id;
  234. $params['mall_id'] = $this->mall_id;
  235. SecondaryCardOrderService::orderRefund($params);
  236. return $this->success('操作成功');
  237. } catch (\Exception $e) {
  238. return $this->error($e->getMessage());
  239. }
  240. }
  241. }
  242. public function actionUseLogList()
  243. {
  244. try {
  245. $params = \Yii::$app->request->get();
  246. $params['mall_id'] = $this->mall_id;
  247. $params['user_id'] = $this->user_id;
  248. $data = SecondaryCardUseLogService::getPageListByH5($params);
  249. return $this->success('操作成功', $data);
  250. } catch (\Exception $e) {
  251. return $this->error($e->getMessage());
  252. }
  253. }
  254. public function actionStoreCateList()
  255. {
  256. try {
  257. $params = \Yii::$app->request->get();
  258. $params['mall_id'] = $this->mall_id;
  259. $params['user_id'] = $this->user_id;
  260. $data = SecondaryCardService::getStoreCateList($params);
  261. return $this->success('操作成功', $data);
  262. } catch (\Exception $e) {
  263. return $this->error($e->getMessage());
  264. }
  265. }
  266. public function actionGetEmployeeSelection()
  267. {
  268. $params = \Yii::$app->request->get();
  269. $params['mall_id'] = $this->mall_id;
  270. $data = SecondaryCardService::getEmployeeSelection($this->mall_id, $params['store_id']);
  271. return $this->success('操作成功', $data);
  272. }
  273. }