| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- <?php
- /**
- * @link:http://www.gdqijianshi.com/
- * @copyright: Copyright (c) 2020 广东七件事集团
- * Created by PhpStorm
- * Author: ganxiaohao
- * Date: 2020-05-08
- * Time: 15:47
- */
- namespace addons\Store\client\controllers;
- use addons\Store\common\models\StoreBossSettingForm;
- use addons\Store\common\models\StoreBossIncome;
- use addons\Store\common\models\StoreBoss;
- use addons\Store\common\models\StoreBossListForm;
- use addons\Store\common\models\StoreBossUserEditForm;
- use addons\Store\common\enums\LevelEnum;
- use addons\Store\common\models\StoreUser;
- use common\enums\StatusEnum;
- use common\models\user\User;
- /**
- * 门店股东
- * Class StoreBossController
- * @package addons\Store\client\controllers
- */
- class StoreBossController extends BaseController
- {
- /**
- * @Author: 广东七件事
- * Date: 2021-08-10
- * Time: 21:35
- * @Note:股东列表
- * @return string|\yii\web\Response
- * @throws \Exception
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- } else {
- $form = new StoreBossListForm();
- $form->attributes = \Yii::$app->request->get();
- $form->store_id = $this->store_id;
- return $this->asJson($form->getList());
- }
- }
- return $this->render('/boss/index');
- }
- /**
- * @Author: 广东七件事
- * Date: 2021-08-10
- * Time: 21:36
- * @Note:修改备注
- */
- public function actionRemarksEdit()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $params = \Yii::$app->request->post();
- $boss = StoreBoss::findOne(['id' => $params['id'], 'status' => 1, 'store_id' => $this->store_id]);
- if (!$boss) {
- return $this->error('该门店股东不存在');
- }
- $boss->remarks = $params['remarks'];
- if (!$boss->save()) {
- return $this->error('保存失败');
- }
- return $this->success('保存成功');
- }
- }
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-11
- * @Time: 15:36
- * @Note:查找用户
- */
- public function actionSearchUser()
- {
- if (\Yii::$app->request->isAjax) {
- $where = [
- ['mall_id' => $this->mall_id],
- ['store_id' => $this->store_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ];
- $get = \Yii::$app->request->get();
- $user_where = [];
- if (!empty($get['nickname_or_mobile'])) {
- $user_where[] = [
- 'OR',
- ['like', 'mobile', $get['nickname_or_mobile'] . '%', false],
- ['like', 'nickname', $get['nickname_or_mobile'] . '%', false]
- ];
- }
- if (!empty($get['level'])) {
- $user_where[] = ['level' => $get['level']];
- }
- if (!empty($get['user_id'])) {
- $user_where[] = ['id' => $get['user_id']];
- }
- if (!empty($user_where)) {
- $user_list = User::lists(['where' => $user_where, 'select' => 'id']);
- $user_id_arr = array_column($user_list, 'id');
- $where[] = ['user_id' => $user_id_arr];
- }
- $params = [
- 'where' => $where,
- 'with' => ['user' => function ($query) {
- $query->select('id,avatar_url,nickname,username,mobile');
- }],
- 'order' => 'id desc'
- ];
- $list = StoreUser::listPage($params);
- $return = [];
- foreach ($list['list'] as $user) {
- $return['list'][] = $user['user'];
- }
- return $this->success('success', $return);
- }
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-11
- * @Time: 15:45
- * @Note:
- * @return string|\yii\web\Response
- */
- public function actionEdit()
- {
- if (\Yii::$app->request->isAjax) {
- $form = new StoreBossUserEditForm();
- $form->attributes = \Yii::$app->request->post();
- $form->store_id = $this->store_id;
- return $this->asJson($form->save());
- } else {
- return $this->render('/boss/edit');
- }
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-11
- * @Time: 16:56
- * @Note:修改等级
- * @return \yii\web\Response
- */
- public function actionLevelChange()
- {
- if (\Yii::$app->request->isAjax) {
- $form = new StoreBossUserEditForm();
- $form->attributes = \Yii::$app->request->post();
- $form->store_id = $this->store_id;
- return $this->asJson($form->changeLevel());
- }
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-11
- * @Time: 16:56
- * @Note:批量修改股东等级
- * @return \yii\web\Response
- */
- public function actionBatchLevel()
- {
- if (\Yii::$app->request->isAjax) {
- $form = new StoreBossUserEditForm();
- $form->attributes = \Yii::$app->request->post();
- $form->store_id = $this->store_id;
- return $this->asJson($form->batchLevel());
- }
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-07-10
- * @Time: 9:18
- * @Note:股东设置
- * @return string|\yii\web\Response
- */
- public function actionSetting()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $form = new StoreBossSettingForm();
- $form->attributes = \Yii::$app->request->post();
- return $this->asJson($form->setDate());
- } else {
- $form = new StoreBossSettingForm();
- return $this->asJson($form->search());
- }
- }
- return $this->render('/boss/setting');
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-07-10
- * @Time: 9:19
- * @Note:提成明细
- */
- public function actionIncomeList()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $form = new StoreBossIncome();
- $param = \Yii::$app->request->post();
- $param['store_id'] = $this->store_id;
- $param['mall_id'] = $this->mall_id;
- return $this->asJson($form->getList($param));
- }
- }
- return $this->render('/boss/income-list');
- }
- /**
- * @Author: 广东七件事 zal
- * @Date: 2020-07-10
- * @Time: 9:19
- * @Note:结算列表
- */
- public function actionSettlementList()
- {
- $retuest = \Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isPost) {
- // 检查提交的参数
- $params = $retuest->post();
- $form = new StoreBossIncome();
- return $this->asJson($form->getSettlementList($params));
- }
- }
- return $this->render('/boss/settlement-list');
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-08-21
- * @Time: 20:02
- * @Note:经销商删除
- */
- public function actionDelete()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $id = \Yii::$app->request->post('id');
- $agent = StoreBoss::findOne(['id' => $id, 'status' => 1]);
- if (!$agent) {
- return $this->asJson(['code' => 1, 'msg' => '该股东不存在或者已被删除!']);
- }
- $agent->status = 0;
- if (!$agent->save()) {
- return $this->asJson(['code' => 1, 'msg' => '删除失败!', 'error' => $agent->getErrors()]);
- }
- return $this->asJson(['code' => 0, 'msg' => '删除成功!']);
- }
- }
- }
- }
|