canyin-project/ybcy/controllers/admin/UserController.php
2024-11-01 16:07:54 +08:00

102 lines
3.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\controllers\admin;
use Illuminate\Support\Facades\DB;
use Yii;
use yii\web\Controller;
use yii\web\Response;
use app\model\user;
class UserController extends CommonController{
//获取用户列表参数keyword,status
public function actionUserList(){
$request = Yii::$app->request;
if ($request->isPost){
$result=axios_request();
$keyword=$result['keyword'];
$satus=$result['status']?$result['status']:2;
$sql="select * from {{%ybwm_users}} where status=".$satus;
if($keyword){
$sql.=" and CONCAT(IFNULL(username,''),IFNULL(phone,'')) LIKE CONCAT('%','$keyword','%')";
}
$data= YII::$app->db->createCommand($sql)->queryAll();
$count=count($data);
return $this->result(1,'成功',$data,$count);
}
return $this->result(2,'请求异常');
}
//用户添加
public function actionSave(){
$request = Yii::$app->request;
if($request->isPost){
$result=axios_request();
$res= YII::$app->db->createCommand('select * from {{%ybwm_users}} where username=:username', ['username' =>trim($result['username'])])->queryOne();
if($res){
return $this->result(2,'用户名已存在');
}else{
$salt=random(8);
$auth_key=Yii::$app->params['authkey'];
$password=sha1(trim($result['password']).'--'.$salt.'--'.$auth_key);
$data=array(
'uniacid'=>$result['uniacid'],
'phone'=>trim($result['phone']),
'headimgurl'=>$result['headimgurl'],
'username'=>trim($result['username']),
'salt'=>$salt,
'password'=>$password,
'joindate'=>date('Y-m-d H:i:s',time()),
'joinip'=>getIp(),
'lastvisit'=>date('Y-m-d H:i:s',time()),
'register_type'=>0,
);
$re= YII::$app->db->createCommand()->insert('{{%ybwm_users}}',$data)->execute();
if($re){
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
}
return $this->result(2,'请求异常');
}
//用户信息编辑
public function actionUsave(){
$request = Yii::$app->request;
if($request->isPost){
$result=axios_request();
$res= YII::$app->db->createCommand('select * from {{%ybwm_users}} where uid=:uid', ['uid' =>$result['uid']])->queryOne();
if(!$res){
return $this->result(2,'用户不存在');
}else{
$data=array('phone'=>$result['phone']);
if(trim($result['password'])!==$res['password']){
$data['password']=$salt=random(8);
$auth_key=Yii::$app->params['authkey'];
$data['password']=sha1(trim($result['password']).'--'.$salt.'--'.$auth_key);
}
$re=YII::$app->db->createCommand()->update('{{%ybwm_users}}', $data, 'uid=:uid', ['uid' =>$result['uid']])->execute();
if($re!==false){
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
}
return $this->result(2,'请求异常');
}
public function actionDelete(){
}
public function actionDemo()
{
$keyword='17607186026';
$sql="select * from users where status=2";
$sql.=" and CONCAT(username,phone) LIKE CONCAT('%',#{$keyword},'%')";
dd($sql);die;
}
}