StoreController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace addons\Happiness\api\modules\v1\controllers;
  3. use addons\Happiness\common\service\StoreService;
  4. use common\enums\GoodsTypeEnum;
  5. use common\enums\OrderCommentEnum;
  6. use common\enums\StatusEnum;
  7. use common\helpers\LocationHelper;
  8. use common\models\common\Region;
  9. use common\models\goods\GoodsCateRelate;
  10. use common\models\order\OrderComments;
  11. use common\models\user\User;
  12. use common\models\user\UserLevel;
  13. use common\logic\common\GoodsLogic;
  14. use Yii;
  15. use Exception;
  16. use api\controllers\OnAuthController;
  17. /**
  18. * 幸福小店门店
  19. *
  20. * Class DefaultController
  21. * @package addons\Store\api\modules\v1\controllers
  22. */
  23. class StoreController extends OnAuthController
  24. {
  25. public $modelClass = '';
  26. /**
  27. * 不用进行登录验证的方法
  28. *
  29. * 例如: ['index', 'update', 'create', 'view', 'delete']
  30. * 默认全部需要验证
  31. *
  32. * @var array
  33. */
  34. protected $authOptional = ['index', 'detail', 'cate-goods-list', 'list', 'recommend', 'comments-list', 'get-platform-goods'];
  35. //获取门店列表
  36. public function actionGetStoreList()
  37. {
  38. $request = Yii::$app->request;
  39. if ($request->isGet) {
  40. try {
  41. $get = $request->get();
  42. $res = Yii::$app->services->validate->validate($get, [
  43. [['page', 'limit', 'shipping_type'], 'integer'],
  44. [['longitude', 'latitude', 'keyword', 'attr_id', 'attr_ids', 'goods_ids'], 'string'],
  45. ]);
  46. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  47. if (!empty($get['attr_ids'])) $get['attr_ids'] = explode(',', $get['attr_ids']);
  48. if (!empty($get['goods_ids'])) $get['goods_ids'] = explode(',', $get['goods_ids']);
  49. $list = (new StoreService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->getStoreList($get);
  50. return $this->success('获取成功', $list);
  51. } catch (\Exception $e) {
  52. return $this->error($e->getMessage());
  53. }
  54. }
  55. }
  56. //匹配最近门店
  57. public function actionGetStore()
  58. {
  59. $request = Yii::$app->request;
  60. if ($request->isGet) {
  61. try {
  62. $get = $request->get();
  63. $res = Yii::$app->services->validate->validate($get, [
  64. [['longitude', 'latitude', 'shipping_type', 'attr_id', 'attr_ids', 'goods_ids'], 'string'],
  65. ]);
  66. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  67. $get['mall_id'] = $this->mall_id;
  68. $get['user_id'] = $this->user_id;
  69. if (!empty($get['attr_ids'])) $get['attr_ids'] = explode(',', $get['attr_ids']);
  70. if (!empty($get['goods_ids'])) $get['goods_ids'] = explode(',', $get['goods_ids']);
  71. $info = (new StoreService())->getStore($get);
  72. return $this->success('获取成功', $info);
  73. } catch (\Exception $e) {
  74. return $this->error($e->getMessage());
  75. }
  76. }
  77. }
  78. //获取历史门店
  79. public function actionGetHistory()
  80. {
  81. $request = Yii::$app->request;
  82. if ($request->isGet) {
  83. try {
  84. $get = $request->get();
  85. $res = Yii::$app->services->validate->validate($get, [
  86. [['longitude', 'latitude'], 'string']
  87. ]);
  88. $list = (new StoreService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->getHistoryStore($get);
  89. return $this->success('获取成功', ['list' => $list]);
  90. } catch (\Exception $e) {
  91. return $this->error($e->getMessage());
  92. }
  93. }
  94. }
  95. //删除历史门店
  96. public function actionDelHistoryStore()
  97. {
  98. $request = Yii::$app->request;
  99. if ($request->isPost) {
  100. try {
  101. $post = $request->post();
  102. $res = Yii::$app->services->validate->validate($post, [
  103. [['id'], 'integer'],
  104. ]);
  105. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  106. $res = (new StoreService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->delHistoryStore($post);
  107. return $this->success('操作成功');
  108. } catch (\Exception $e) {
  109. return $this->error($e->getMessage());
  110. }
  111. }
  112. }
  113. //获取门店详情
  114. public function actionGetStoreDetail()
  115. {
  116. $request = Yii::$app->request;
  117. if ($request->isGet) {
  118. try {
  119. $get = $request->get();
  120. $res = Yii::$app->services->validate->validate($get, [
  121. [['store_id'], 'integer'],
  122. [['longitude', 'latitude'], 'string'],
  123. ]);
  124. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  125. $info = (new StoreService(['mall_id' => $this->mall_id]))->getStoreDetail($get);
  126. return $this->success('获取成功', $info);
  127. } catch (\Exception $e) {
  128. return $this->error($e->getMessage());
  129. }
  130. }
  131. }
  132. }