StoreBossController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. /**
  3. * @link:http://www.gdqijianshi.com/
  4. * @copyright: Copyright (c) 2020 广东七件事集团
  5. * Created by PhpStorm
  6. * Author: ganxiaohao
  7. * Date: 2020-05-08
  8. * Time: 15:47
  9. */
  10. namespace addons\Store\client\controllers;
  11. use addons\Store\common\models\StoreBossSettingForm;
  12. use addons\Store\common\models\StoreBossIncome;
  13. use addons\Store\common\models\StoreBoss;
  14. use addons\Store\common\models\StoreBossListForm;
  15. use addons\Store\common\models\StoreBossUserEditForm;
  16. use addons\Store\common\enums\LevelEnum;
  17. use addons\Store\common\models\StoreUser;
  18. use common\enums\StatusEnum;
  19. use common\models\user\User;
  20. /**
  21. * 门店股东
  22. * Class StoreBossController
  23. * @package addons\Store\client\controllers
  24. */
  25. class StoreBossController extends BaseController
  26. {
  27. /**
  28. * @Author: 广东七件事
  29. * Date: 2021-08-10
  30. * Time: 21:35
  31. * @Note:股东列表
  32. * @return string|\yii\web\Response
  33. * @throws \Exception
  34. */
  35. public function actionIndex()
  36. {
  37. if (\Yii::$app->request->isAjax) {
  38. if (\Yii::$app->request->isPost) {
  39. } else {
  40. $form = new StoreBossListForm();
  41. $form->attributes = \Yii::$app->request->get();
  42. $form->store_id = $this->store_id;
  43. return $this->asJson($form->getList());
  44. }
  45. }
  46. return $this->render('/boss/index');
  47. }
  48. /**
  49. * @Author: 广东七件事
  50. * Date: 2021-08-10
  51. * Time: 21:36
  52. * @Note:修改备注
  53. */
  54. public function actionRemarksEdit()
  55. {
  56. if (\Yii::$app->request->isAjax) {
  57. if (\Yii::$app->request->isPost) {
  58. $params = \Yii::$app->request->post();
  59. $boss = StoreBoss::findOne(['id' => $params['id'], 'status' => 1, 'store_id' => $this->store_id]);
  60. if (!$boss) {
  61. return $this->error('该门店股东不存在');
  62. }
  63. $boss->remarks = $params['remarks'];
  64. if (!$boss->save()) {
  65. return $this->error('保存失败');
  66. }
  67. return $this->success('保存成功');
  68. }
  69. }
  70. }
  71. /**
  72. * @Author: 广东七件事 ganxiaohao
  73. * @Date: 2020-05-11
  74. * @Time: 15:36
  75. * @Note:查找用户
  76. */
  77. public function actionSearchUser()
  78. {
  79. if (\Yii::$app->request->isAjax) {
  80. $where = [
  81. ['mall_id' => $this->mall_id],
  82. ['store_id' => $this->store_id],
  83. ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
  84. ];
  85. $get = \Yii::$app->request->get();
  86. $user_where = [];
  87. if (!empty($get['nickname_or_mobile'])) {
  88. $user_where[] = [
  89. 'OR',
  90. ['like', 'mobile', $get['nickname_or_mobile'] . '%', false],
  91. ['like', 'nickname', $get['nickname_or_mobile'] . '%', false]
  92. ];
  93. }
  94. if (!empty($get['level'])) {
  95. $user_where[] = ['level' => $get['level']];
  96. }
  97. if (!empty($get['user_id'])) {
  98. $user_where[] = ['id' => $get['user_id']];
  99. }
  100. if (!empty($user_where)) {
  101. $user_list = User::lists(['where' => $user_where, 'select' => 'id']);
  102. $user_id_arr = array_column($user_list, 'id');
  103. $where[] = ['user_id' => $user_id_arr];
  104. }
  105. $params = [
  106. 'where' => $where,
  107. 'with' => ['user' => function ($query) {
  108. $query->select('id,avatar_url,nickname,username,mobile');
  109. }],
  110. 'order' => 'id desc'
  111. ];
  112. $list = StoreUser::listPage($params);
  113. $return = [];
  114. foreach ($list['list'] as $user) {
  115. $return['list'][] = $user['user'];
  116. }
  117. return $this->success('success', $return);
  118. }
  119. }
  120. /**
  121. * @Author: 广东七件事 ganxiaohao
  122. * @Date: 2020-05-11
  123. * @Time: 15:45
  124. * @Note:
  125. * @return string|\yii\web\Response
  126. */
  127. public function actionEdit()
  128. {
  129. if (\Yii::$app->request->isAjax) {
  130. $form = new StoreBossUserEditForm();
  131. $form->attributes = \Yii::$app->request->post();
  132. $form->store_id = $this->store_id;
  133. return $this->asJson($form->save());
  134. } else {
  135. return $this->render('/boss/edit');
  136. }
  137. }
  138. /**
  139. * @Author: 广东七件事 ganxiaohao
  140. * @Date: 2020-05-11
  141. * @Time: 16:56
  142. * @Note:修改等级
  143. * @return \yii\web\Response
  144. */
  145. public function actionLevelChange()
  146. {
  147. if (\Yii::$app->request->isAjax) {
  148. $form = new StoreBossUserEditForm();
  149. $form->attributes = \Yii::$app->request->post();
  150. $form->store_id = $this->store_id;
  151. return $this->asJson($form->changeLevel());
  152. }
  153. }
  154. /**
  155. * @Author: 广东七件事 ganxiaohao
  156. * @Date: 2020-05-11
  157. * @Time: 16:56
  158. * @Note:批量修改股东等级
  159. * @return \yii\web\Response
  160. */
  161. public function actionBatchLevel()
  162. {
  163. if (\Yii::$app->request->isAjax) {
  164. $form = new StoreBossUserEditForm();
  165. $form->attributes = \Yii::$app->request->post();
  166. $form->store_id = $this->store_id;
  167. return $this->asJson($form->batchLevel());
  168. }
  169. }
  170. /**
  171. * @Author: 广东七件事 ganxiaohao
  172. * @Date: 2020-07-10
  173. * @Time: 9:18
  174. * @Note:股东设置
  175. * @return string|\yii\web\Response
  176. */
  177. public function actionSetting()
  178. {
  179. if (\Yii::$app->request->isAjax) {
  180. if (\Yii::$app->request->isPost) {
  181. $form = new StoreBossSettingForm();
  182. $form->attributes = \Yii::$app->request->post();
  183. return $this->asJson($form->setDate());
  184. } else {
  185. $form = new StoreBossSettingForm();
  186. return $this->asJson($form->search());
  187. }
  188. }
  189. return $this->render('/boss/setting');
  190. }
  191. /**
  192. * @Author: 广东七件事 ganxiaohao
  193. * @Date: 2020-07-10
  194. * @Time: 9:19
  195. * @Note:提成明细
  196. */
  197. public function actionIncomeList()
  198. {
  199. if (\Yii::$app->request->isAjax) {
  200. if (\Yii::$app->request->isPost) {
  201. $form = new StoreBossIncome();
  202. $param = \Yii::$app->request->post();
  203. $param['store_id'] = $this->store_id;
  204. $param['mall_id'] = $this->mall_id;
  205. return $this->asJson($form->getList($param));
  206. }
  207. }
  208. return $this->render('/boss/income-list');
  209. }
  210. /**
  211. * @Author: 广东七件事 zal
  212. * @Date: 2020-07-10
  213. * @Time: 9:19
  214. * @Note:结算列表
  215. */
  216. public function actionSettlementList()
  217. {
  218. $retuest = \Yii::$app->request;
  219. if ($retuest->isAjax) {
  220. if ($retuest->isPost) {
  221. // 检查提交的参数
  222. $params = $retuest->post();
  223. $form = new StoreBossIncome();
  224. return $this->asJson($form->getSettlementList($params));
  225. }
  226. }
  227. return $this->render('/boss/settlement-list');
  228. }
  229. /**
  230. * @Author: 广东七件事 ganxiaohao
  231. * @Date: 2020-08-21
  232. * @Time: 20:02
  233. * @Note:经销商删除
  234. */
  235. public function actionDelete()
  236. {
  237. if (\Yii::$app->request->isAjax) {
  238. if (\Yii::$app->request->isPost) {
  239. $id = \Yii::$app->request->post('id');
  240. $agent = StoreBoss::findOne(['id' => $id, 'status' => 1]);
  241. if (!$agent) {
  242. return $this->asJson(['code' => 1, 'msg' => '该股东不存在或者已被删除!']);
  243. }
  244. $agent->status = 0;
  245. if (!$agent->save()) {
  246. return $this->asJson(['code' => 1, 'msg' => '删除失败!', 'error' => $agent->getErrors()]);
  247. }
  248. return $this->asJson(['code' => 0, 'msg' => '删除成功!']);
  249. }
  250. }
  251. }
  252. }