request; if ($retuest->isAjax) { if ($retuest->isGet) { $get = Yii::$app->request->get(); // 检查提交的参数 $res = Yii::$app->services->validate->validate($get,[ [['id','level'], 'integer'], [['id','keyword'], 'safe'], ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 获取股东等级 //$level_list = AddonsBossLevel::getBossLevel([['mall_id' => $this->mall_id]],[],true,'level,name'); // 升级类型 //$upgrade_type = LevelEnum::getUpgradeType(); $where = $parents = $list = []; $where[] = ['=', 'status', StatusEnum::ENABLED]; $where[] = ['=', 'mall_id', $this->mall_id]; !empty($get['level']) && $where[] = ['=', 'level', $get['level']]; // 根据搜索手机号查询用户id if (!empty($get['keyword'])) { $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'mobile', $get['keyword'] . '%', false])->asArray()->column(); if (empty($user_ids)) $this->success('获取成功', compact('list','level_list', 'upgrade_type', 'parents')); $where[] = ['in', 'user_id', $user_ids]; } $with = ['user']; $order = 'created_at desc'; $params = array('where' => $where, 'order'=>$order, 'with' => $with, 'limit' => $get['limit']); $list = BossThree::listPage($params, false, true); if (isset($list['list'])) { // 获取用户上级推荐人id $parent_ids = []; foreach ($list['list'] as $boss) { $parent_ids[] = $boss['user']['parent_id']; } if ($parent_ids) { // 获取上级用户信息 $parents = User::getUserList([['in','id',array_unique($parent_ids)]], 'id,nickname', [], 1); $parents = array_column($parents, 'nickname', 'id'); } } $this->success('获取成功', compact('list', 'parents')); } } else { return $this->render($this->action->id); } } /** * 添加股东 * @Author: lun * @DateTime: 2021/10/21 0021 17:56 * @Copyright: copyright (c) 2021 广东七件事集团 */ public function actionAddBoss() { $retuest = Yii::$app->request; if ($retuest->isAjax) { if ($retuest->isPost) { $params = Yii::$app->request->post(); $params['level'] = 0; $res = Yii::$app->services->validate->validate($params,[[['mobile','level'], 'integer'], [['mobile','level'], 'required']]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 根据手机号码获取用户id $user = User::getOne([['mall_id' => $this->mall_id], ['mobile' => $params['mobile']]],true,[],false,'id'); if (empty($user)) return $this->error('暂无此用户'); $params['mall_id'] = $this->mall_id; $params['user_id'] = $user['id']; $params['goods_ids'] = ''; // 保存数据 $res = BossThree::setData($params); if (!$res) return $this->error(BossThree::getStaticError()); $this->success('添加成功'); } } } /** * 根据用户名搜索用户 * @Author: lun * @DateTime: 2021/10/21 0021 18:36 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionSelectUser() { $retuest = Yii::$app->request; if ($retuest->isAjax && $retuest->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params,[[['keyword'], 'string'], [['keyword'], 'required']]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 搜索用户列表 $list = User::getUserList([['mall_id' => $this->mall_id],['like','mobile',$params['keyword']]], 'id,mobile', [], 1); $this->success('获取成功', $list); } } /** * 股东数据编辑 * @Author: lun * @DateTime: 2021/10/23 0023 9:20 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionEdit() { $retuest = Yii::$app->request; if ($retuest->isAjax) { if ($retuest->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params,[ [['user_id'], 'required'], [['remark'], 'string'], [['user_id','status','level'], 'integer'] ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params = BossThree::exceptNullVal($params); $params['mall_id'] = $this->mall_id; // 保存数据 $res = BossThree::setData($params); if (!$res) return $this->error(BossThree::getStaticError()); $this->success('修改成功'); } } } /** * 商品编辑 * @return mixed|string|void */ public function actionGoods() { $retuest = Yii::$app->request; if ($retuest->isAjax) { if ($retuest->isPost) { $id = Yii::$app->request->get('id'); $post = Yii::$app->request->post(); // 检查提交的参数 $labels = [ 'price' => '抽取百分比', 'goods_ids' => '商品', ]; $res = Yii::$app->services->validate->validate($post,[ [['goods_ids','percent'], 'required'], [['goods_ids'], 'string'], [['price'], 'number','min' => 0, 'max' => 100], ],$labels); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $data = BossThree::findOne(['id' => $id,'mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED]); if(!$data){ return $this->error('数据不存在'); } $data->goods_ids = $post['goods_ids'] ?: ''; $data->is_percent = 0; $data->price = $post['price'] ?: 0; if($data->save()){ return $this->success('保存成功'); }else{ return $this->error(BossThree::getStaticError()); } }else{ $id = Yii::$app->request->get('id'); $data = BossThree::findOne(['id' => $id,'mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED]); if($data){ $data = $data->toArray(); $goods_list = []; if($data['goods_ids']){ $goods_list = Goods::find() ->select('id as goods_id,goods_name,price,original_price,cover_pic,status,stock as goods_stock') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => explode(',',$data['goods_ids'])]) ->asArray() ->all(); } } $this->success('获取成功', compact('data','goods_list')); } } return $this->render($this->action->id); } }