validate()) { return $this->responseErrorInfo(); } $store = \Yii::$app->session->get('o2o'); $where[]=['=','status' ,1]; $where[]=['=','mall_id', $store['mall_id']]; $where[]=['=','store_id', $store['id']]; if(!empty($this->keyword)){ $where[]=['like', 'nickname', $this->keyword]; } $params['order'] = 'id desc'; $params['where'] = $where; $params['limit'] = 10; $params['select'] = 'id ,nickname'; $lists = User::listPage($params, false); return [ 'code' => 0, 'msg' => '', 'data' => [ 'list' => $lists['list'] ] ]; } public function save() { if (!$this->validate()) { return $this->responseErrorInfo(); } try { /* @var User $user */ $user = User::findOne(['id' => $this->id, 'status' => 1]); if (!$user) { return ['code' => 1, 'msg' => '用户不存在']; } if($this->store_id){ $store = Store::getOne([['id'=>$this->store_id]],true); }else{ $store = \Yii::$app->session->get('o2o'); } $boss = StoreBoss::findOne(['user_id' => $user->id,'store_id' => $store['id'], 'status' => 1]); if ($boss) { return ['code' => 1, 'msg' => '此用户已经是该门店股东,请勿重复提交']; } else { $boss = new StoreBoss(); $boss->mall_id = $user->mall_id; $boss->user_id = $user->id; $boss->store_id = $store['id']; $boss->created_at = time(); } $t = \Yii::$app->db->beginTransaction(); try { $boss->level=$this->level; $boss->status = 1; if ($boss->save()) { $t->commit(); return ['code' => 0, 'msg' => '保存成功']; } else { return $this->responseErrorMsg($boss); } } catch (\Exception $exception) { $t->rollBack(); return [ 'code' => 1, 'msg' => $exception->getMessage() ]; } } catch (\Exception $exception) { return [ 'code' => 1, 'msg' => $exception->getMessage() ]; } } public function changeLevel() { if (!$this->validate()) { return $this->responseErrorInfo(); } try { $common = new StoreBossLevelCommon; $common->userId = $this->id; if ($this->level) { $bossLevel = $common->getBossLevelByLevel($this->level,$this->store_id); if (!$bossLevel) { throw new \Exception('无效的股东等级'); } } else { $this->level = 0; } $res = $common->changeLevel($this->level,StoreBoss::UPGRADE_STATUS_MANUAL,$this->store_id); if ($res) { return [ 'code' => 0, 'msg' => '修改成功' ]; } else { return [ 'code' => 1, 'msg' => $res ]; } } catch (\Exception $exception) { return [ 'code' =>1, 'msg' => $exception->getMessage() ]; } } public function batchLevel() { if (!$this->validate()) { return $this->responseErrorInfo(); } try { if ($this->level) { $common = new StoreBossLevelCommon; $bossLevel = $common->getBossLevelByLevel($this->level); if (!$bossLevel) { throw new \Exception('无效的股东等级'); } } else { $this->level = 0; } StoreBoss::updateAll( ['level' => $this->level, 'upgrade_level_at' => time()], ['id' => $this->batch_ids] ); return [ 'code' => 0, 'msg' => '修改成功' ]; } catch (\Exception $exception) { return [ 'code' => 1, 'msg' => $exception->getMessage() ]; } } }