|
@@ -1,54 +1,60 @@
|
|
|
<?php
|
|
|
-declare (strict_types = 1);
|
|
|
+declare (strict_types=1);
|
|
|
|
|
|
namespace app\controller;
|
|
|
|
|
|
use app\BaseController;
|
|
|
-use app\model\Account;use app\model\AccountCompany;use think\App;
|
|
|
-use think\Exception;use think\facade\Db;use think\facade\Validate;
|
|
|
+use app\model\Account;
|
|
|
+use app\model\AccountCompany;
|
|
|
+use think\App;
|
|
|
+use think\Exception;
|
|
|
+use think\facade\Db;
|
|
|
+use think\facade\Validate;
|
|
|
|
|
|
class UserInfo extends BaseController
|
|
|
{
|
|
|
- public function __construct(App $app) {
|
|
|
- parent::__construct($app);
|
|
|
- }
|
|
|
- /**
|
|
|
- * @param string $nickname
|
|
|
- * @param string $username
|
|
|
- * @param int $status
|
|
|
- * @param array $uid
|
|
|
- * @param array $nuid
|
|
|
- * @param int $page
|
|
|
- * @param int $size
|
|
|
- * @param string $nickname
|
|
|
- * @return \think\response\Json
|
|
|
- * @throws \think\db\exception\DbException
|
|
|
- */
|
|
|
- public function UserList()
|
|
|
+ public function __construct(App $app)
|
|
|
{
|
|
|
- $post=$this->request->only(["nickname"=>"","username"=>"","status"=>"","companyNo"=>"","uid"=>[],"nuid"=>[], "page"=>1,"size"=>10,'level'=>''],"post");
|
|
|
- $condition = [["a.is_del","=",0]];
|
|
|
- isset($post['nickname'])&& $post['nickname']!="" ? $condition[]=["nickname","like","%{$post['nickname']}%"] : "";
|
|
|
- isset($post['username'])&& $post['username']!="" ? $condition[]=["username","like","%{$post['username']}%"] : "";
|
|
|
- isset($post['status'])&& $post['status']!=="" ? $condition[]=["a.status","=",$post['status']] : "";
|
|
|
- isset($post['uid'])&& !empty($post['uid']) ? $condition[]=["a.id","in",$post['uid']] : "";
|
|
|
- isset($post['nuid'])&& !empty($post['nuid']) ? $condition[]=["a.id","not in",$post['nuid']] : "";
|
|
|
- isset($post['level'])&& !empty($post['level']) ? $condition[]=["a.level",'=',$post['level']] : "";
|
|
|
+ parent::__construct($app);
|
|
|
+ }
|
|
|
|
|
|
- if ($post['companyNo']!=""){
|
|
|
- $uid =Db::name("account_company")->where(["companyCode"=>$post['companyNo'],"is_del"=>0])->column("account_id");
|
|
|
- $condition[]=["a.id","in",$uid];
|
|
|
+ /**
|
|
|
+ * @param string $nickname
|
|
|
+ * @param string $username
|
|
|
+ * @param int $status
|
|
|
+ * @param array $uid
|
|
|
+ * @param array $nuid
|
|
|
+ * @param int $page
|
|
|
+ * @param int $size
|
|
|
+ * @param string $nickname
|
|
|
+ * @return \think\response\Json
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ */
|
|
|
+ public function UserList()
|
|
|
+ {
|
|
|
+ $post = $this->request->only(["nickname" => "", "username" => "", "status" => "", "companyNo" => "", "uid" => [], "nuid" => [], "page" => 1, "size" => 10, 'level' => ''], "post");
|
|
|
+ $condition = [["a.is_del", "=", 0]];
|
|
|
+ isset($post['nickname']) && $post['nickname'] != "" ? $condition[] = ["nickname", "like", "%{$post['nickname']}%"] : "";
|
|
|
+ isset($post['username']) && $post['username'] != "" ? $condition[] = ["username", "like", "%{$post['username']}%"] : "";
|
|
|
+ isset($post['status']) && $post['status'] !== "" ? $condition[] = ["a.status", "=", $post['status']] : "";
|
|
|
+ isset($post['uid']) && !empty($post['uid']) ? $condition[] = ["a.id", "in", $post['uid']] : "";
|
|
|
+ isset($post['nuid']) && !empty($post['nuid']) ? $condition[] = ["a.id", "not in", $post['nuid']] : "";
|
|
|
+ isset($post['level']) && !empty($post['level']) ? $condition[] = ["a.level", '=', $post['level']] : "";
|
|
|
+
|
|
|
+ if ($post['companyNo'] != "") {
|
|
|
+ $uid = Db::name("account_company")->where(["companyCode" => $post['companyNo'], "is_del" => 0])->column("account_id");
|
|
|
+ $condition[] = ["a.id", "in", $uid];
|
|
|
}
|
|
|
- $page = isset($post['page'])&& $post['page']!=="" ? intval($post['page']) : 1;
|
|
|
- $size = isset($post['size'])&& $post['size']!=="" ? intval($post['size']) : 10;
|
|
|
+ $page = isset($post['page']) && $post['page'] !== "" ? intval($post['page']) : 1;
|
|
|
+ $size = isset($post['size']) && $post['size'] !== "" ? intval($post['size']) : 10;
|
|
|
$count = Db::name("account")->alias("a")
|
|
|
- ->leftJoin("user b","a.id=b.account_id and b.status=1")
|
|
|
- ->where($condition)->count();
|
|
|
- $total =intval(ceil($count/$size)) ;
|
|
|
- $page = $total>=$page? $page:$total;
|
|
|
- $list = Db::name("account")->alias("a")
|
|
|
- ->leftJoin("user b","a.id=b.account_id and b.status=1")
|
|
|
- ->append(['plat', 'company_relaton'])
|
|
|
+ ->leftJoin("user b", "a.id=b.account_id and b.status=1")
|
|
|
+ ->where($condition)->count();
|
|
|
+ $total = intval(ceil($count / $size));
|
|
|
+ $page = $total >= $page ? $page : $total;
|
|
|
+ $list = Db::name("account")->alias("a")
|
|
|
+ ->leftJoin("user b", "a.id=b.account_id and b.status=1")
|
|
|
+ ->append(['plat', 'company_relaton'])
|
|
|
// ->withAttr('plat', function ($val, $da) {
|
|
|
// return Db::name("account_plat")
|
|
|
// ->alias("a")
|
|
@@ -65,253 +71,261 @@ class UserInfo extends BaseController
|
|
|
->select()
|
|
|
->toArray();
|
|
|
})
|
|
|
- ->where($condition)->page($page,$size)->order("a.id desc")
|
|
|
- ->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime")
|
|
|
- ->select()->toArray();
|
|
|
+ ->where($condition)->page($page, $size)->order("a.id desc")
|
|
|
+ ->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime")
|
|
|
+ ->select()->toArray();
|
|
|
|
|
|
- return json_show(0,"获取成功",["list"=>$list,"count"=>$count]);
|
|
|
- }
|
|
|
+ return json_show(0, "获取成功", ["list" => $list, "count" => $count]);
|
|
|
+ }
|
|
|
|
|
|
- /** @param int $id 账户id
|
|
|
- * @return \think\response\Json
|
|
|
- */
|
|
|
+ /** @param int $id 账户id
|
|
|
+ * @return \think\response\Json
|
|
|
+ */
|
|
|
public function info()
|
|
|
{
|
|
|
- $post=$this->request->only(["id"=>""],"post","intval");
|
|
|
- if($post['id']==""){
|
|
|
- return json_show(1003,"参数 id 不能为空");
|
|
|
+ $post = $this->request->only(["id" => ""], "post", "intval");
|
|
|
+ if ($post['id'] == "") {
|
|
|
+ return json_show(1003, "参数 id 不能为空");
|
|
|
}
|
|
|
- $list = Db::name("account")->alias("a")
|
|
|
- ->leftJoin("user b","a.id=b.account_id and b.status=1")
|
|
|
- ->where(["a.id"=>$post['id'],"a.is_del"=>0])
|
|
|
- ->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime")
|
|
|
- ->findOrEmpty();
|
|
|
- if(empty($list)){
|
|
|
- return json_show(1004,"未找到用户信息");
|
|
|
+ $list = Db::name("account")->alias("a")
|
|
|
+ ->leftJoin("user b", "a.id=b.account_id and b.status=1")
|
|
|
+ ->where(["a.id" => $post['id'], "a.is_del" => 0])
|
|
|
+ ->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime")
|
|
|
+ ->findOrEmpty();
|
|
|
+ if (empty($list)) {
|
|
|
+ return json_show(1004, "未找到用户信息");
|
|
|
}
|
|
|
// $list['plat']= Db::name("account_plat")->alias("a")
|
|
|
// ->leftJoin("platform b","a.plat_code=b.plat_code and b.status=1")
|
|
|
// ->where(["a.status"=>1,"a.is_del"=>0,"a.account_id"=>$list['id']])->column("a.plat_code,plat_name");
|
|
|
- $list['company_relaton'] = Db::name("account_company")->where(["account_id"=>$list['id'],"is_del"=>0,"status"=>1])
|
|
|
- ->column("companyCode,companyName,company_type,is_main,status");
|
|
|
- return json_show(0,"获取成功",$list);
|
|
|
+ $list['company_relaton'] = Db::name("account_company")->where(["account_id" => $list['id'], "is_del" => 0, "status" => 1])
|
|
|
+ ->column("companyCode,companyName,company_type,is_main,status");
|
|
|
+ return json_show(0, "获取成功", $list);
|
|
|
}
|
|
|
- /**
|
|
|
- * @return \think\response\Json|void
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\DbException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- */
|
|
|
- public function PassSet()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return \think\response\Json|void
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function PassSet()
|
|
|
{
|
|
|
- $post=$this->request->only(["id"=>"","password"=>""],"post","trim");
|
|
|
- $validate=Validate::rule([
|
|
|
- 'id|账户ID' => 'require|number',
|
|
|
- 'password|密码' => 'require|min:6|max:200',
|
|
|
- ]);
|
|
|
- if($validate->check($post)==false) return json_show(1004,$validate->getError());
|
|
|
- $account=Db::name("account")->where([["id","=",$post['id']],["is_del","=","0"]])->find();
|
|
|
- if(empty($account)){
|
|
|
- return json_show(1003,"账户不存在");
|
|
|
+ $post = $this->request->only(["id" => "", "password" => ""], "post", "trim");
|
|
|
+ $validate = Validate::rule([
|
|
|
+ 'id|账户ID' => 'require|number',
|
|
|
+ 'password|密码' => 'require|min:6|max:200',
|
|
|
+ ]);
|
|
|
+ if ($validate->check($post) == false) return json_show(1004, $validate->getError());
|
|
|
+ $account = Db::name("account")->where([["id", "=", $post['id']], ["is_del", "=", "0"]])->find();
|
|
|
+ if (empty($account)) {
|
|
|
+ return json_show(1003, "账户不存在");
|
|
|
}
|
|
|
|
|
|
- $salt=makeSalt();
|
|
|
- $password = sha1($post['password'].$salt);
|
|
|
- $account['password']=$password;
|
|
|
- $account['salt']=$salt;
|
|
|
- $account['is_pass']=1;
|
|
|
- $account['updatetime']=date("Y-m-d H:i:s");
|
|
|
- $up = Db::name("account")->save($account);
|
|
|
- return $up?json_show(0,"密码修改成功"):json_show(1005,"密码修改失败");
|
|
|
+ $salt = makeSalt();
|
|
|
+ $password = sha1($post['password'] . $salt);
|
|
|
+ $account['password'] = $password;
|
|
|
+ $account['salt'] = $salt;
|
|
|
+ $account['is_pass'] = 1;
|
|
|
+ $account['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $up = Db::name("account")->save($account);
|
|
|
+ return $up ? json_show(0, "密码修改成功") : json_show(1005, "密码修改失败");
|
|
|
}
|
|
|
- /**@param int $id
|
|
|
- *@param array $company
|
|
|
- * @return \think\response\Json
|
|
|
- */
|
|
|
- public function setCompany(){
|
|
|
- $post = $this->request->only(["id"=>"","company"=>[]],"post");
|
|
|
- $validate=Validate::rule([
|
|
|
- 'id|账户ID' => 'require|number|gt:0',
|
|
|
- 'company|业务公司' => 'require|array',
|
|
|
- ]);
|
|
|
- if($validate->check($post)==false) return json_show(1004,$validate->getError());
|
|
|
- $company_insert=[];
|
|
|
- $acount =new AccountCompany();
|
|
|
- foreach ($post['company'] as $company){
|
|
|
- $ist=$acount->where(["account_id"=>$post['id'],"companyCode"=>$company['companyCode'],"is_del"=>0])->find();
|
|
|
- if($ist!=false)$company['id']=$ist['id'];
|
|
|
- $company_insert[]=[
|
|
|
- "id"=>$company['id']??null,
|
|
|
- "account_id"=>$post['id'],
|
|
|
- "companyCode"=>$company['companyCode'],
|
|
|
- "companyName"=>$company['companyName'],
|
|
|
- "company_type"=>$company['company_type'],
|
|
|
- "is_main"=>$company['is_main'],
|
|
|
- "status"=>1,
|
|
|
- "is_del"=>$company['is_del']??0,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
- ];
|
|
|
- }
|
|
|
|
|
|
- $inser =$acount->saveAll($company_insert);
|
|
|
- return $inser?json_show(0,"关联企业设置成功"):json_show(1005,"关联企业设置失败");
|
|
|
+ /**@param int $id
|
|
|
+ * @param array $company
|
|
|
+ * @return \think\response\Json
|
|
|
+ */
|
|
|
+ public function setCompany()
|
|
|
+ {
|
|
|
+ $post = $this->request->only(["id" => "", "company" => []], "post");
|
|
|
+ $validate = Validate::rule([
|
|
|
+ 'id|账户ID' => 'require|number|gt:0',
|
|
|
+ 'company|业务公司' => 'require|array',
|
|
|
+ ]);
|
|
|
+ if ($validate->check($post) == false) return json_show(1004, $validate->getError());
|
|
|
+ $company_insert = [];
|
|
|
+ $acount = new AccountCompany();
|
|
|
+ foreach ($post['company'] as $company) {
|
|
|
+ $ist = $acount->where(["account_id" => $post['id'], "companyCode" => $company['companyCode'], "is_del" => 0])->find();
|
|
|
+ if ($ist != false) $company['id'] = $ist['id'];
|
|
|
+ $company_insert[] = [
|
|
|
+ "id" => $company['id'] ?? null,
|
|
|
+ "account_id" => $post['id'],
|
|
|
+ "companyCode" => $company['companyCode'],
|
|
|
+ "companyName" => $company['companyName'],
|
|
|
+ "company_type" => $company['company_type'],
|
|
|
+ "is_main" => $company['is_main'],
|
|
|
+ "status" => 1,
|
|
|
+ "is_del" => $company['is_del'] ?? 0,
|
|
|
+ "addtime" => date("Y-m-d H:i:s"),
|
|
|
+ "updatetime" => date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $inser = $acount->saveAll($company_insert);
|
|
|
+ return $inser ? json_show(0, "关联企业设置成功") : json_show(1005, "关联企业设置失败");
|
|
|
}
|
|
|
- /**
|
|
|
- * @param int $id
|
|
|
- * @param int $status
|
|
|
- * @return \think\response\Json
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public function setCompanyStatus(){
|
|
|
- $post = $this->request->only(["account_id"=>"","companyCode"=>'',"status"=>""],"post");
|
|
|
- $validate=Validate::rule([
|
|
|
- 'account_id|账户id' => 'require|number|gt:0',
|
|
|
- 'status|状态' => 'require|number|in:0,1',
|
|
|
- 'companyCode|公司编号' => 'require',
|
|
|
- ]);
|
|
|
- if($validate->check($post)==false) return json_show(1004,$validate->getError());
|
|
|
- $account = Db::name("account")->where(["id"=>$post['account_id'],"is_del"=>0])->findOrEmpty();
|
|
|
- if(empty($account))return json_show(1004,"未找账户到数据");
|
|
|
- $acc = new AccountCompany();
|
|
|
- $info= $acc->where(["account_id"=>$post['account_id'],"companyCode"=>$post['companyCode'],"is_del"=>0])
|
|
|
- ->findOrEmpty();
|
|
|
- if($info->isEmpty()){
|
|
|
- return json_show(1004,"未找账户到数据");
|
|
|
- }
|
|
|
- $upda=["status"=>$post['status'],"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
- $inser=$acc->update($upda,["account_id"=>$post['account_id'],"companyCode"=>$post['companyCode'],"is_del"=>0]);
|
|
|
- if($inser==false) return json_show(1005,"关联企业状态设置失败");
|
|
|
- $count = $acc->where([["account_id","=",$post['account_id']],["status","<>",$post['status']],["is_del","=",0]])->count();
|
|
|
- if($count==0 && $account['status']!=$post['status'])Db::name("account")->where(["id"=>$post['account_id'],"is_del"=>0])->update($upda);
|
|
|
- return json_show(0,"关联企业状态设置成功");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param int $id
|
|
|
+ * @param int $status
|
|
|
+ * @return \think\response\Json
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function setCompanyStatus()
|
|
|
+ {
|
|
|
+ $post = $this->request->only(["account_id" => "", "companyCode" => '', "status" => ""], "post");
|
|
|
+ $validate = Validate::rule([
|
|
|
+ 'account_id|账户id' => 'require|number|gt:0',
|
|
|
+ 'status|状态' => 'require|number|in:0,1',
|
|
|
+ 'companyCode|公司编号' => 'require',
|
|
|
+ ]);
|
|
|
+ if ($validate->check($post) == false) return json_show(1004, $validate->getError());
|
|
|
+ $account = Db::name("account")->where(["id" => $post['account_id'], "is_del" => 0])->findOrEmpty();
|
|
|
+ if (empty($account)) return json_show(1004, "未找账户到数据");
|
|
|
+ $acc = new AccountCompany();
|
|
|
+ $info = $acc->where(["account_id" => $post['account_id'], "companyCode" => $post['companyCode'], "is_del" => 0])
|
|
|
+ ->findOrEmpty();
|
|
|
+ if ($info->isEmpty()) {
|
|
|
+ return json_show(1004, "未找账户到数据");
|
|
|
+ }
|
|
|
+ $upda = ["status" => $post['status'], "updatetime" => date("Y-m-d H:i:s")];
|
|
|
+ $inser = $acc->update($upda, ["account_id" => $post['account_id'], "companyCode" => $post['companyCode'], "is_del" => 0]);
|
|
|
+ if ($inser == false) return json_show(1005, "关联企业状态设置失败");
|
|
|
+ $count = $acc->where([["account_id", "=", $post['account_id']], ["status", "<>", $post['status']], ["is_del", "=", 0]])->count();
|
|
|
+ if ($count == 0 && $account['status'] != $post['status']) Db::name("account")->where(["id" => $post['account_id'], "is_del" => 0])->update($upda);
|
|
|
+ return json_show(0, "关联企业状态设置成功");
|
|
|
}
|
|
|
- /**
|
|
|
- * @param int $id
|
|
|
- * @param string $nickname
|
|
|
- * @param int $mobile
|
|
|
- * @param string $email
|
|
|
- * @param string $portrait
|
|
|
- * @param int $sex
|
|
|
- * @return \think\response\Json
|
|
|
- */
|
|
|
- public function UserSave()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param int $id
|
|
|
+ * @param string $nickname
|
|
|
+ * @param int $mobile
|
|
|
+ * @param string $email
|
|
|
+ * @param string $portrait
|
|
|
+ * @param int $sex
|
|
|
+ * @return \think\response\Json
|
|
|
+ */
|
|
|
+ public function UserSave()
|
|
|
{
|
|
|
$post = $this->request->only([
|
|
|
- "id"=>"",
|
|
|
- "nickname"=>"",
|
|
|
- "mobile"=>"",
|
|
|
- "email"=>"",
|
|
|
- "portrait"=>"",
|
|
|
- "sex"=>"",
|
|
|
- ],"post");
|
|
|
- $validate=Validate::rule([
|
|
|
- 'id|主键ID' => 'require|number|gt:0',
|
|
|
- 'nickname|名称' => 'require|max:255',
|
|
|
- 'mobile|手机号' => 'require|number|length:11|mobile',
|
|
|
- 'email|名称' => 'email',
|
|
|
- 'sex|性别' => 'number|in:0,1,2',
|
|
|
- ]);
|
|
|
- if($validate->check($post)==false) return json_show(1004,$validate->getError());
|
|
|
- $account=Db::name("account")->where([["id","=",$post['id']],["is_del","=",0]])->findOrEmpty();
|
|
|
- if(empty($account)){
|
|
|
- return json_show(1003,"账户不存在");
|
|
|
+ "id" => "",
|
|
|
+ "nickname" => "",
|
|
|
+ "mobile" => "",
|
|
|
+ "email" => "",
|
|
|
+ "portrait" => "",
|
|
|
+ "sex" => "",
|
|
|
+ ], "post");
|
|
|
+ $validate = Validate::rule([
|
|
|
+ 'id|主键ID' => 'require|number|gt:0',
|
|
|
+ 'nickname|名称' => 'require|max:255',
|
|
|
+ 'mobile|手机号' => 'require|number|length:11|mobile',
|
|
|
+ 'email|名称' => 'email',
|
|
|
+ 'sex|性别' => 'number|in:0,1,2',
|
|
|
+ ]);
|
|
|
+ if ($validate->check($post) == false) return json_show(1004, $validate->getError());
|
|
|
+ $account = Db::name("account")->where([["id", "=", $post['id']], ["is_del", "=", 0]])->findOrEmpty();
|
|
|
+ if (empty($account)) {
|
|
|
+ return json_show(1003, "账户不存在");
|
|
|
}
|
|
|
- $accountinfo=Db::name("user")->where([["account_id","=",$post['id']]])->findOrEmpty();
|
|
|
- if(empty($accountinfo)){
|
|
|
- return json_show(1003,"账户信息不存在");
|
|
|
+ $accountinfo = Db::name("user")->where([["account_id", "=", $post['id']]])->findOrEmpty();
|
|
|
+ if (empty($accountinfo)) {
|
|
|
+ return json_show(1003, "账户信息不存在");
|
|
|
}
|
|
|
- $uiq = Db::table("sys_account")->where([["mobile","=",$post['mobile']],["id","<>",$post['id']],["is_del","=",0]])->find();
|
|
|
- if($uiq){
|
|
|
- return json_show(1002,"手机号已存在!");
|
|
|
+ $uiq = Db::table("sys_account")->where([["mobile", "=", $post['mobile']], ["id", "<>", $post['id']], ["is_del", "=", 0]])->find();
|
|
|
+ if ($uiq) {
|
|
|
+ return json_show(1002, "手机号已存在!");
|
|
|
}
|
|
|
Db::startTrans();
|
|
|
- try{
|
|
|
- $userinfo=[
|
|
|
- "nickname"=>$post['nickname'],
|
|
|
- "mobile"=>$post['mobile'],
|
|
|
- "email"=>$post['email'],
|
|
|
- "portrait"=>$post['portrait'],
|
|
|
- "sex"=>$post['sex'],
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- $dat=Db::name("user")->where($accountinfo)->update($userinfo);
|
|
|
- if($dat==false){
|
|
|
- Db::rollback();
|
|
|
- return json_show(1004,"信息修改失败");
|
|
|
- }
|
|
|
- $acc= [
|
|
|
- "id"=>$post['id'],
|
|
|
- "mobile"=>$post['mobile'],
|
|
|
- "username"=>$post['mobile'],
|
|
|
- "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
- ];
|
|
|
- $nu = Db::name("account")->save($acc);
|
|
|
- if($nu){
|
|
|
- Db::commit();
|
|
|
- return json_show(0,"信息修改成功");
|
|
|
- }else{
|
|
|
- Db::rollback();
|
|
|
- return json_show(1004,"账户信息修改失败");
|
|
|
- }
|
|
|
- }catch (\Exception $e){
|
|
|
+ try {
|
|
|
+ $userinfo = [
|
|
|
+ "nickname" => $post['nickname'],
|
|
|
+ "mobile" => $post['mobile'],
|
|
|
+ "email" => $post['email'],
|
|
|
+ "portrait" => $post['portrait'],
|
|
|
+ "sex" => $post['sex'],
|
|
|
+ "updatetime" => date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $dat = Db::name("user")->where($accountinfo)->update($userinfo);
|
|
|
+ if ($dat == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(1004, "信息修改失败");
|
|
|
+ }
|
|
|
+ $acc = [
|
|
|
+ "id" => $post['id'],
|
|
|
+ "mobile" => $post['mobile'],
|
|
|
+ "username" => $post['mobile'],
|
|
|
+ "updatetime" => date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ $nu = Db::name("account")->save($acc);
|
|
|
+ if ($nu) {
|
|
|
+ Db::commit();
|
|
|
+ return json_show(0, "信息修改成功");
|
|
|
+ } else {
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(1004, "账户信息修改失败");
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
Db::rollback();
|
|
|
- return json_show(1005,$e->getMessage());
|
|
|
+ return json_show(1005, $e->getMessage());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- /**
|
|
|
- * @param int $id
|
|
|
- * @param int $status
|
|
|
- * @return \think\response\Json
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public function UserStatus()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param int $id
|
|
|
+ * @param int $status
|
|
|
+ * @return \think\response\Json
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function UserStatus()
|
|
|
{
|
|
|
- $post = $this->request->only(["id"=>"","status"=>""],"post","trim");
|
|
|
- $validate=Validate::rule([
|
|
|
- 'id|主键ID' => 'require|number|gt:0',
|
|
|
- 'status|状态' => 'require|number|in:0,1',
|
|
|
- ]);
|
|
|
- if($validate->check($post)==false) return json_show(1004,$validate->getError());
|
|
|
- $account=Account::where("id",$post['id'])->findOrEmpty();
|
|
|
- if($account->isEmpty()){
|
|
|
- return json_show(1003,"账户不存在");
|
|
|
+ $post = $this->request->only(["id" => "", "status" => ""], "post", "trim");
|
|
|
+ $validate = Validate::rule([
|
|
|
+ 'id|主键ID' => 'require|number|gt:0',
|
|
|
+ 'status|状态' => 'require|number|in:0,1',
|
|
|
+ ]);
|
|
|
+ if ($validate->check($post) == false) return json_show(1004, $validate->getError());
|
|
|
+ $account = Account::where("id", $post['id'])->findOrEmpty();
|
|
|
+ if ($account->isEmpty()) {
|
|
|
+ return json_show(1003, "账户不存在");
|
|
|
}
|
|
|
- if($account['status']==$post['status']){
|
|
|
- return json_show(1004,"数据已更新");
|
|
|
+ if ($account['status'] == $post['status']) {
|
|
|
+ return json_show(1004, "数据已更新");
|
|
|
}
|
|
|
- $message = $post['status']==1?"启用":"禁用";
|
|
|
+ $message = $post['status'] == 1 ? "启用" : "禁用";
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
- $result= Db::name("account")->where("id","=",$post['id'])->save(['status'=>$post['status'],"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
- if($result){
|
|
|
- $ip= AccountCompany::update(['status'=>$post['status'],"updatetime"=>date("Y-m-d H:i:s")], ["account_id"=>$post['id'],"is_del"=>0]);
|
|
|
- if($ip){
|
|
|
- Db::commit();
|
|
|
- return json_show(0,"账户{$message}成功");
|
|
|
+ $result = Db::name("account")->where("id", "=", $post['id'])->save(['status' => $post['status'], "updatetime" => date("Y-m-d H:i:s")]);
|
|
|
+ if ($result) {
|
|
|
+ $ip = AccountCompany::update(['status' => $post['status'], "updatetime" => date("Y-m-d H:i:s")], ["account_id" => $post['id'], "is_del" => 0]);
|
|
|
+ if ($ip) {
|
|
|
+ Db::commit();
|
|
|
+ return json_show(0, "账户{$message}成功");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- Db::rollback();
|
|
|
- return json_show(1005,"账户{$message}失败");
|
|
|
- }catch (\Exception $e){
|
|
|
- Db::rollback();
|
|
|
- return json_show(1004,$e->getMessage());
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(1005, "账户{$message}失败");
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(1004, $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
- //根据业务公司获取用户数据
|
|
|
+
|
|
|
+ //根据业务公司获取用户数据
|
|
|
public function UserListByCompany()
|
|
|
{
|
|
|
- $post = $this->request->only(["nickname" => "", "username" => "", "status" => "", "uid" => [], "nuid" => [], "companyNo" => "", "page" => 1, "size" => 10], "post");
|
|
|
+ $post = $this->request->only(["nickname" => "", "username" => "", "status" => "", "uid" => [], "nuid" => [], "companyNo" => "", "page" => 1, "size" => 10, 'islevel' => ''], "post");
|
|
|
$condition = [["a.is_del", "=", 0]];
|
|
|
$whereor = [];
|
|
|
isset($post['nickname']) && $post['nickname'] != "" ? $condition[] = ["nickname", "like", "%{$post['nickname']}%"] : "";
|
|
|
isset($post['username']) && $post['username'] != "" ? $condition[] = ["username", "like", "%{$post['username']}%"] : "";
|
|
|
isset($post['status']) && $post['status'] !== "" ? $condition[] = ["a.status", "=", $post['status']] : "";
|
|
|
- isset($post['uid']) && !empty($post['uid'])&& !empty($post['uid']) ? $condition[] = ["a.id", "in", $post['uid']] : "";
|
|
|
- isset($post['nuid']) &&!empty($post['nuid']) && !empty($post['nuid']) ? $condition[] = ["a.id", "not in", $post['nuid']] : "";
|
|
|
- isset($post['companyNo']) && $post['companyNo'] !== "" ? $condition[] = ["c.companyCode", "=", $post['companyNo']]
|
|
|
- : $whereor[] = ["c.companyCode", "=", null];
|
|
|
+ isset($post['uid']) && !empty($post['uid']) && !empty($post['uid']) ? $condition[] = ["a.id", "in", $post['uid']] : "";
|
|
|
+ isset($post['nuid']) && !empty($post['nuid']) && !empty($post['nuid']) ? $condition[] = ["a.id", "not in", $post['nuid']] : "";
|
|
|
+ isset($post['companyNo']) && $post['companyNo'] !== "" ? $condition[] = ["c.companyCode", "=", $post['companyNo']] : $whereor[] = ["c.companyCode", "=", null];
|
|
|
+ if ($post['islevel'] !== '') $condition[] = ['a.level', '=', $post['level']];
|
|
|
|
|
|
$page = isset($post['page']) && $post['page'] !== "" ? intval($post['page']) : 1;
|
|
|
$size = isset($post['size']) && $post['size'] !== "" ? intval($post['size']) : 10;
|
|
@@ -326,7 +340,7 @@ class UserInfo extends BaseController
|
|
|
$page = $total >= $page ? $page : $total;
|
|
|
$list = Db::name("account")
|
|
|
->alias("a")
|
|
|
- ->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime,companyCode,companyName,company_type,is_main,c.status as com_status")
|
|
|
+ ->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime,companyCode,companyName,company_type,is_main,c.status as com_status,a.level")
|
|
|
->leftJoin("user b", "a.id=b.account_id and b.status=1")
|
|
|
->leftJoin("account_company c", "a.id=c.account_id and c.is_del=0")
|
|
|
->where($condition)
|
|
@@ -355,100 +369,101 @@ class UserInfo extends BaseController
|
|
|
return json_show(0, "获取成功", ["list" => $list, "count" => $count]);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return \think\response\Json
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\DbException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- */
|
|
|
- public function userAdd(){
|
|
|
- $post = $this->request->only(["nickname"=>"","mobile"=>"","email"=>"","companyArr"=>[]],"post","trim");
|
|
|
- $validate=Validate::rule([
|
|
|
- 'nickname|真实姓名' => 'require|min:2|max:200',
|
|
|
- 'mobile|手机号' => 'require|number|length:11|mobile',
|
|
|
- 'email|邮箱' => 'email',
|
|
|
- 'companyArr|关联业务公司' => 'array',
|
|
|
- ]);
|
|
|
- if($validate->check($post)==false) return json_show(1004,$validate->getError());
|
|
|
+ /**
|
|
|
+ * @return \think\response\Json
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function userAdd()
|
|
|
+ {
|
|
|
+ $post = $this->request->only(["nickname" => "", "mobile" => "", "email" => "", "companyArr" => []], "post", "trim");
|
|
|
+ $validate = Validate::rule([
|
|
|
+ 'nickname|真实姓名' => 'require|min:2|max:200',
|
|
|
+ 'mobile|手机号' => 'require|number|length:11|mobile',
|
|
|
+ 'email|邮箱' => 'email',
|
|
|
+ 'companyArr|关联业务公司' => 'array',
|
|
|
+ ]);
|
|
|
+ if ($validate->check($post) == false) return json_show(1004, $validate->getError());
|
|
|
Db::startTrans();
|
|
|
- $uiq = Db::table("sys_account")->where(["mobile"=>$post['mobile']])->find();
|
|
|
- if($uiq){
|
|
|
- return json_show(1002,"手机号已注册!");
|
|
|
+ $uiq = Db::table("sys_account")->where(["mobile" => $post['mobile']])->find();
|
|
|
+ if ($uiq) {
|
|
|
+ return json_show(1002, "手机号已注册!");
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- $salt =makeSalt();
|
|
|
- $password = sha1("dingding123".$salt);
|
|
|
+ $salt = makeSalt();
|
|
|
+ $password = sha1("dingding123" . $salt);
|
|
|
$data = [
|
|
|
- 'username'=>$post['mobile'],
|
|
|
- "password"=>$password,
|
|
|
- "salt"=>$salt,
|
|
|
- "mobile"=>$post['mobile'],
|
|
|
- "source"=>"paltadd",
|
|
|
- "status"=>1,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- $reuslt = Db::table('sys_account')->insert($data,true);
|
|
|
- if($reuslt){
|
|
|
- $data=[
|
|
|
- "nickname"=>$post['nickname'],
|
|
|
- "mobile"=>$post['mobile'],
|
|
|
- "email"=>$post['email'],
|
|
|
- "portrait"=>"",
|
|
|
- "sex"=>1,
|
|
|
- "post"=>"",
|
|
|
- "department"=>"",
|
|
|
- "account_id"=>$reuslt,
|
|
|
- "status"=>1,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ 'username' => $post['mobile'],
|
|
|
+ "password" => $password,
|
|
|
+ "salt" => $salt,
|
|
|
+ "mobile" => $post['mobile'],
|
|
|
+ "source" => "paltadd",
|
|
|
+ "status" => 1,
|
|
|
+ "addtime" => date("Y-m-d H:i:s"),
|
|
|
+ "updatetime" => date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $reuslt = Db::table('sys_account')->insert($data, true);
|
|
|
+ if ($reuslt) {
|
|
|
+ $data = [
|
|
|
+ "nickname" => $post['nickname'],
|
|
|
+ "mobile" => $post['mobile'],
|
|
|
+ "email" => $post['email'],
|
|
|
+ "portrait" => "",
|
|
|
+ "sex" => 1,
|
|
|
+ "post" => "",
|
|
|
+ "department" => "",
|
|
|
+ "account_id" => $reuslt,
|
|
|
+ "status" => 1,
|
|
|
+ "addtime" => date("Y-m-d H:i:s"),
|
|
|
+ "updatetime" => date("Y-m-d H:i:s")
|
|
|
];
|
|
|
- $user=Db::table("sys_user")->insert($data);
|
|
|
- if($user!=false){
|
|
|
- $acount =new AccountCompany();
|
|
|
- if(!empty($post['companyArr'])){
|
|
|
- $company_insert=[];
|
|
|
- foreach ($post['companyArr'] as $company){
|
|
|
- $company_insert[]=[
|
|
|
- "account_id"=>$reuslt,
|
|
|
- "companyCode"=>$company['companyCode'],
|
|
|
- "companyName"=>$company['companyName'],
|
|
|
- "company_type"=>$company['company_type'],
|
|
|
- "is_main"=>$company['is_main'],
|
|
|
- "status"=>1,
|
|
|
- "is_del"=>0,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
- ];
|
|
|
- }
|
|
|
- $u= $acount->saveAll($company_insert);
|
|
|
- }else{
|
|
|
- $company_insert=[
|
|
|
- "account_id"=>$reuslt,
|
|
|
- "companyCode"=>'',
|
|
|
- "companyName"=>'',
|
|
|
- "company_type"=>'0',
|
|
|
- "is_main"=>1,
|
|
|
- "status"=>1,
|
|
|
- "is_del"=>0,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
- ];
|
|
|
- $u= $acount->save($company_insert);
|
|
|
- }
|
|
|
+ $user = Db::table("sys_user")->insert($data);
|
|
|
+ if ($user != false) {
|
|
|
+ $acount = new AccountCompany();
|
|
|
+ if (!empty($post['companyArr'])) {
|
|
|
+ $company_insert = [];
|
|
|
+ foreach ($post['companyArr'] as $company) {
|
|
|
+ $company_insert[] = [
|
|
|
+ "account_id" => $reuslt,
|
|
|
+ "companyCode" => $company['companyCode'],
|
|
|
+ "companyName" => $company['companyName'],
|
|
|
+ "company_type" => $company['company_type'],
|
|
|
+ "is_main" => $company['is_main'],
|
|
|
+ "status" => 1,
|
|
|
+ "is_del" => 0,
|
|
|
+ "addtime" => date("Y-m-d H:i:s"),
|
|
|
+ "updatetime" => date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $u = $acount->saveAll($company_insert);
|
|
|
+ } else {
|
|
|
+ $company_insert = [
|
|
|
+ "account_id" => $reuslt,
|
|
|
+ "companyCode" => '',
|
|
|
+ "companyName" => '',
|
|
|
+ "company_type" => '0',
|
|
|
+ "is_main" => 1,
|
|
|
+ "status" => 1,
|
|
|
+ "is_del" => 0,
|
|
|
+ "addtime" => date("Y-m-d H:i:s"),
|
|
|
+ "updatetime" => date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ $u = $acount->save($company_insert);
|
|
|
+ }
|
|
|
|
|
|
- if($u==false)throw new Exception("账户新建失败");
|
|
|
- Db::commit();
|
|
|
- return json_show(0,"账户注册成功",["userid"=>$reuslt,"nickname"=>$post['nickname']]);
|
|
|
+ if ($u == false) throw new Exception("账户新建失败");
|
|
|
+ Db::commit();
|
|
|
+ return json_show(0, "账户注册成功", ["userid" => $reuslt, "nickname" => $post['nickname']]);
|
|
|
}
|
|
|
}
|
|
|
Db::rollback();
|
|
|
- return json_show(1002,"账户注册失败");
|
|
|
+ return json_show(1002, "账户注册失败");
|
|
|
|
|
|
- }catch (\Exception $e){
|
|
|
+ } catch (\Exception $e) {
|
|
|
Db::rollback();
|
|
|
- return json_show(1002,"账户注册失败".$e->getMessage());
|
|
|
+ return json_show(1002, "账户注册失败" . $e->getMessage());
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|