StoreBossLevelController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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: 16:10
  9. */
  10. namespace addons\Store\client\controllers;
  11. use addons\Store\common\models\StoreBossLevelCommon;
  12. use addons\Store\common\models\StoreBossLevelForm;
  13. use addons\Store\common\models\StoreBossLevel;
  14. use common\enums\StatusEnum;
  15. use Yii;
  16. /**
  17. * 门店股东等级设置
  18. * Class StoreBossLevelController
  19. * @package addons\Store\client\controllers
  20. */
  21. class StoreBossLevelController extends BaseController
  22. {
  23. /**
  24. * @Author: 广东七件事 ganxiaohao
  25. * @Date: 2020-05-12
  26. * @Time: 9:52
  27. * @Note:等级列表
  28. * @return string|\yii\web\Response
  29. */
  30. public function actionIndex()
  31. {
  32. if (\Yii::$app->request->isAjax) {
  33. if (\Yii::$app->request->isPost) {
  34. } elseif (\Yii::$app->request->isGet) {
  35. $params = \Yii::$app->request->get();
  36. $where[] = ['=', 'mall_id', $this->mall_id];
  37. $where[] = ['=','store_id', $this->store_id];
  38. $where[] = ['=','is_delete', 0];
  39. if($params['keyword']){
  40. $where[]=['or', ['like', 'name',$params['keyword']], ['like', 'level', $params['keyword']]];
  41. }
  42. $params = [
  43. 'select' => '*',
  44. 'where' => $where,
  45. 'order' => 'level asc',
  46. 'page' => $params['page'],
  47. 'limit' => 20,
  48. ];
  49. $lists = StoreBossLevel::listPage($params, false, true);
  50. $data= [
  51. 'code' => 0,
  52. 'msg' => '',
  53. 'data' => [
  54. 'list' => $lists['list'],
  55. 'pagination' => $lists['pagination']
  56. ]
  57. ];
  58. return $this->asJson($data);
  59. }
  60. }
  61. return $this->render('/store-boss-level/index');
  62. }
  63. /**
  64. * @Author: 广东七件事 ganxiaohao
  65. * Date: 2020-05-10
  66. * Time: 22:26
  67. * @Note:已经启用的等级
  68. */
  69. public function actionEnableList()
  70. {
  71. if (\Yii::$app->request->isAjax) {
  72. if (\Yii::$app->request->isGet) {
  73. $where = [['mall_id' => $this->mall_id], ['store_id'=>$this->store_id],['is_enable'=>1],['=', 'status', StatusEnum::ENABLED]];
  74. $args['where'] = $where;
  75. $args['select'] = 'id,level,name';
  76. $args['order'] = 'level asc';
  77. $list['list'] = StoreBossLevel::lists($args, true);
  78. return $this->success('操作成功', $list);
  79. }
  80. }
  81. return $this->error();
  82. }
  83. /**
  84. * @Author: 广东七件事 ganxiaohao
  85. * @Date: 2020-05-12
  86. * @Time: 9:23
  87. * @Note:编辑
  88. * @return string|\yii\web\Response
  89. */
  90. public function actionEdit()
  91. {
  92. if (\Yii::$app->request->isAjax) {
  93. if (\Yii::$app->request->isPost) {
  94. $form = new StoreBossLevelForm();
  95. $form->attributes = \Yii::$app->request->post('form');
  96. $form->store_id = $this->store_id;
  97. $form->mall_id = $this->mall_id;
  98. return $this->asJson($form->setData( ));
  99. } elseif (\Yii::$app->request->isGet) {
  100. $form = new StoreBossLevelForm();
  101. $form->attributes=\Yii::$app->request->get();
  102. return $this->asJson($form->getDetail());
  103. }
  104. }
  105. return $this->render('/store-boss-level/edit');
  106. }
  107. /**
  108. * @Author: 广东七件事 ganxiaohao
  109. * @Date: 2020-05-12
  110. * @Time: 9:52
  111. * @Note:等级状态变更
  112. * @return \yii\web\Response
  113. */
  114. public function actionSwitchStatus()
  115. {
  116. $level = StoreBossLevel::findOne(['id' => \Yii::$app->request->post('id'),'store_id' => $this->store_id, 'is_delete' => 0]);
  117. if (!$level) {
  118. return $this->asJson([
  119. 'code' => 1,
  120. 'msg' => '该等级不存在或已被删除!',
  121. ]);
  122. }
  123. try {
  124. if ($level->is_use) {
  125. $level->is_use = 0;
  126. } else {
  127. $level->is_use = 1;
  128. }
  129. if ($level->save()) {
  130. return $this->asJson([
  131. 'code' =>1,
  132. 'msg' => '分销等级状态变更成功',
  133. ]);
  134. }
  135. } catch (\Exception $exception) {
  136. return $this->asJson([
  137. 'code' => 1,
  138. 'msg' => $exception->getMessage()
  139. ]);
  140. }
  141. }
  142. /**
  143. * @Author: 广东七件事 ganxiaohao
  144. * @Date: 2020-05-12
  145. * @Time: 9:52
  146. * @Note:删除
  147. * @return \yii\web\Response
  148. */
  149. public function actionDelete()
  150. {
  151. if (\Yii::$app->request->isAjax) {
  152. if (\Yii::$app->request->isPost) {
  153. $id = \Yii::$app->request->post('id');
  154. if(!$id){
  155. return $this->error('参数错误');
  156. }
  157. $level = StoreBossLevel::findOne(['id' => $id,'store_id' => $this->store_id, 'is_delete' => 0]);
  158. $level->is_delete = 1;
  159. if (!$level->save()) {
  160. return $this->error($level->getError());
  161. }
  162. return $this->success('操作成功');
  163. }
  164. }
  165. }
  166. /**
  167. * @Author: 广东七件事 ganxiaohao
  168. * @Date: 2020-05-12
  169. * @Time: 9:47
  170. * @Note:获取分销配置以及权重
  171. * @return \yii\web\Response
  172. */
  173. public function actionSetting()
  174. {
  175. $list = (new StoreBossLevelCommon())->getLevelWeights();
  176. return $this->asJson([
  177. 'code' =>0,
  178. 'msg' => '',
  179. 'data' => [
  180. 'weights' => $list['newList'],
  181. 'match_weights' => $list['matchList'],
  182. ]
  183. ]);
  184. }
  185. }