getShopId($this->wqData['uniacid']); $page=Yii::$app->request->get('page')?Yii::$app->request->get('page'):1; $num=($page-1)*10; $limit=10; $query= (new \yii\db\Query()) ->select('a.id,a.sort,userName,a.display,role_name,trueName,phone,a.display,from_unixtime(a.createdAt)createdAt') ->from('{{%ybwm_users}} a') ->leftJoin('{{%ybwm_role_list}} b','a.role_id=b.id') ->where(['a.type'=>$type,'a.uniacid'=>$this->wqData['uniacid'],'a.storeId'=>$storeId]); $sessionData=Yii::$app->session->get('userInfo'); if($sessionData['type']==2){ $query=$query->andWhere(['a.id'=>$sessionData['id']]); } $count=(clone $query)->count(); $data=$query->orderBy('sort asc,id desc') ->offset($num) ->limit($limit) ->all(); return $this->result(1,'成功',$data,$count); } public function actionUserSave(){ $request = Yii::$app->request; if($request->isPost){ $result=axios_request(); if($result['id']){ $row=(new \yii\db\Query()) ->from('{{%ybwm_users}}') ->where(['id'=>$result['id']])->one(); if($result['userName']&&$result['userName']!==$row['userName']){ $info=(new \yii\db\Query()) ->from('{{%ybwm_users}}') ->where(['userName'=>trim($result['userName'])]) ->andWhere(['<>','id',$result['id']])->one(); if($info){ echo json_encode(['code' => 2, 'msg' => '用户名已存在,请更换用户名']);die; } } } if($result['userTel']&&$result['id']){ $query=(new \yii\db\Query())->from('{{%ybwm_apply}} a') ->select('a.id,apply_type,apply_image,apply_name,time_type,start_time,end_time,b.id userId,b.userName') ->leftJoin('{{%ybwm_users}} b','a.id=b.uniacid') ->where(['phone'=>trim($result['userTel']),'b.type'=>1]); //var_dump(ddSql($query));die; $count=count($query->all()); $one=(new \yii\db\Query())->from('{{%ybwm_users}}')->where(['id'=>trim($result['id'])])->one(); $appNumRe=(new \yii\db\Query())->from('{{%ybwm_users}}')->where(['phone'=>trim($result['userTel']),'type'=>1])->one(); if($appNumRe&&trim($result['userTel'])&&trim($result['userTel'])!==$one['phone']){ if($appNumRe['appNum']<=$count){ echo json_encode(['code' => 2, 'msg' => '手机号对应可平台数量达到上限']);die; } } } if($result['id']){ $data=array('userName'=>$result['userName'],'portrait'=>$result['portrait'],'userTel'=>$result['userTel']); if($result['passWord']&&$result['passWord']<>$row['passWord']){ $auth_key=Yii::$app->params['authkey']; $salt=randoms(8); $data['passWord']=trim(checkPassWord($salt,$auth_key,trim($result['passWord']))); } $data['salt']=$salt; $data['role_id']=$result['role_id']; $data['sort']=$result['sort']; $data['trueName']=$result['trueName']; $data['userId']=$result['userId']; $data=filter_array($data); YII::$app->db->createCommand()->update('{{%ybwm_users}}',$data, ['id'=>$result['id']])->execute(); $userInfo=(new \yii\db\Query()) ->from('{{%ybwm_users}}') ->where(['id'=>$result['id']]) ->one(); Yii::$app->session->set('userInfo',$userInfo); }else{ $row=(new \yii\db\Query()) ->from('{{%ybwm_users}}') ->where(['userName'=>trim($result['userName'])])->one(); if($row){ return $this->result(2,'用户名已存在');die; } $salt=randoms(8); $auth_key=Yii::$app->params['authkey']; $storeId=$result['storeId']?:Store::getMainStore($this->wqData['uniacid'])['id']; $data=array( 'sort'=>$result['sort'], 'userName'=>trim($result['userName']), 'passWord'=>checkPassWord($salt,$auth_key,trim($result['passWord'])), 'uniacid'=>$this->wqData['uniacid'], 'role_id'=>$result['role_id'], 'phone'=>$result['userTel']?:$result['phone'], 'salt'=>$salt, 'storeId'=>$storeId, 'portrait'=>$result['portrait'], 'trueName'=>$result['trueName'], 'userId'=>$result['merchantId'], 'createdAt'=>time() ); if($result['type']==4){ $data['type']=4; } YII::$app->db->createCommand()->insert('{{%ybwm_users}}', $data)->execute(); } return $this->result(1,'成功'); } } public function actionChangeUser(){ $request = Yii::$app->request; if($request->isPost){ $result=axios_request(); $id=$result['id']; if(is_array($id)){ $re = YII::$app->db->createCommand()->update('{{%ybwm_users}}', ['display'=>$result['display']], ['in','id',$id])->execute(); }else{ $re = YII::$app->db->createCommand()->update('{{%ybwm_users}}', ['display'=>$result['display']], ['id'=>$id])->execute(); } return $this->result(1,'成功'); } } public function actionUserDel(){ $request = Yii::$app->request; if($request->isPost){ $id=axios_request()['id']; if(is_array($id)){ $re = YII::$app->db->createCommand()->delete('{{%ybwm_users}}', ['in','id',$id])->execute(); }else{ $re = YII::$app->db->createCommand()->delete('{{%ybwm_users}}', ['id'=>$id])->execute(); } return $this->result(1,'成功'); } } //获取当前登陆用户信息 public function actionGetUserInfo(){ $result=axios_request(); $id=Yii::$app->session->get('userInfo')['id']; if($result['id']){ $id=$result['id']; } $request = Yii::$app->request; if($request->isPost) { $data = (new \yii\db\Query()) ->select('userId,id,userName,passWord,portrait,phone,role_id,sort,trueName,userId merchantId') ->from('{{%ybwm_users}}') ->where(['deleteAt' => 0, 'id' =>$id]) ->one(); $info=getSysInfo();$newData=[]; $userData=(new \yii\db\Query()) ->from('{{%ybwm_users}}') ->where(['>','userId','']) ->all(); $ids=array_column($userData,'userId'); $merchantUser=(new \yii\db\Query()) ->select('id,userName') ->from('{{%ybwm_merchant_member}}') ->where(['>','portrait','']) ->andWhere(['not in','id',$ids]) ->all(); if($result['id']){ $res=(new \yii\db\Query()) ->select('id,userName') ->from('{{%ybwm_merchant_member}}') ->where(['id'=>$data['userId']]) ->all()?:[]; $merchantUser=array_merge($merchantUser,$res); } $serviceData=$info['authData']['service']?true:false; $data['merchantUser']=$merchantUser; $data['app']=$serviceData; } return $this->result(1,'成功',$data); } }