|
@@ -1,390 +1,427 @@
|
|
|
<?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\facade\Db;use think\facade\Validate;
|
|
|
+use app\model\Account;
|
|
|
+use app\model\AccountCompany;
|
|
|
+use think\App;
|
|
|
+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"=>"","uid"=>[],"nuid"=>[],"page"=>1,"size"=>10],"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'])&& $post['uid']!=="" ? $condition[]=["a.id","in",$post['uid']] : "";
|
|
|
- isset($post['nuid'])&& $post['nuid']!=="" ? $condition[]=["a.id","not in",$post['nuid']] : "";
|
|
|
- $page = isset($post['page'])&& $post['page']!=="" ? intval($post['page']) : 1;
|
|
|
- $size = isset($post['size'])&& $post['size']!=="" ? intval($post['size']) : 10;
|
|
|
+ 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()
|
|
|
+ {
|
|
|
+ $post = $this->request->only(["nickname" => "", "username" => "", "status" => "", "uid" => [], "nuid" => [], "page" => 1, "size" => 10], "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']) && $post['uid'] !== "" ? $condition[] = ["a.id", "in", $post['uid']] : "";
|
|
|
+ isset($post['nuid']) && $post['nuid'] !== "" ? $condition[] = ["a.id", "not in", $post['nuid']] : "";
|
|
|
+ $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")
|
|
|
- ->where($condition)->page($page,$size)
|
|
|
- ->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime")
|
|
|
- ->cursor();
|
|
|
- $data=[];
|
|
|
- foreach ($list as $item){
|
|
|
- $item['plat']= Db::name("account_plat")->alias("a")
|
|
|
- ->leftJoin("platform b","a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
|
|
|
- ->where(["a.status"=>1,"a.is_del"=>0,"a.account_id"=>$item['id']])->column("a.plat_code,plat_name");
|
|
|
- $item['company_relaton'] = Db::name("account_company")->where(["account_id"=>$item['id'],"is_del"=>0,"status"=>1])
|
|
|
- ->column("companyCode,companyName,company_type,is_main,status");
|
|
|
- $data[]=$item;
|
|
|
+ ->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")
|
|
|
+ ->where($condition)->page($page, $size)
|
|
|
+ ->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime")
|
|
|
+ ->cursor();
|
|
|
+ $data = [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $item['plat'] = Db::name("account_plat")->alias("a")
|
|
|
+ ->leftJoin("platform b", "a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
|
|
|
+ ->where(["a.status" => 1, "a.is_del" => 0, "a.account_id" => $item['id']])->column("a.plat_code,plat_name");
|
|
|
+ $item['company_relaton'] = Db::name("account_company")->where(["account_id" => $item['id'], "is_del" => 0, "status" => 1])
|
|
|
+ ->column("companyCode,companyName,company_type,is_main,status");
|
|
|
+ $data[] = $item;
|
|
|
}
|
|
|
|
|
|
- return json_show(0,"获取成功",["list"=>$data,"count"=>$count]);
|
|
|
- }
|
|
|
+ return json_show(0, "获取成功", ["list" => $data, "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['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);
|
|
|
}
|
|
|
- /**
|
|
|
- * @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'])->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'])->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']])->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']])->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(["id"=>"","status"=>""],"post","intval");
|
|
|
- $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());
|
|
|
- $info=AccountCompany::where(["id"=>$post['id']])->find();
|
|
|
- if($info==false){
|
|
|
- return json_show(1004,"未找到数据");
|
|
|
- }
|
|
|
- if($info['status']==$post['status']){
|
|
|
- return json_show(1004,"数据已更新");
|
|
|
- }
|
|
|
- $info['status']=$post['status'];
|
|
|
- $info['updatetime']=date("Y-m-d H:i:s");
|
|
|
- $inser=AccountCompany::update($info->toArray());
|
|
|
- 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(["id" => "", "status" => ""], "post", "intval");
|
|
|
+ $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());
|
|
|
+ $info = AccountCompany::where(["id" => $post['id']])->find();
|
|
|
+ if ($info == false) {
|
|
|
+ return json_show(1004, "未找到数据");
|
|
|
+ }
|
|
|
+ if ($info['status'] == $post['status']) {
|
|
|
+ return json_show(1004, "数据已更新");
|
|
|
+ }
|
|
|
+ $info['status'] = $post['status'];
|
|
|
+ $info['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $inser = AccountCompany::update($info->toArray());
|
|
|
+ return $inser ? json_show(0, "关联企业状态设置成功") : json_show(1005, "关联企业状态设置失败");
|
|
|
}
|
|
|
- /**
|
|
|
- * @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, "账户信息不存在");
|
|
|
}
|
|
|
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(empty($account)){
|
|
|
- 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 (empty($account)) {
|
|
|
+ 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?"启用":"禁用";
|
|
|
- $result= Db::name("account")->where("id","=",$post['id'])->save(['status'=>$post['status'],"updatetime"=>date("Y-m-d
|
|
|
+ $message = $post['status'] == 1 ? "启用" : "禁用";
|
|
|
+ $result = Db::name("account")->where("id", "=", $post['id'])->save(['status' => $post['status'], "updatetime" => date("Y-m-d
|
|
|
H:i:s")]);
|
|
|
- return $result?json_show(0,"账户{$message}成功") : json_show(1005,"账户{$message}失败");
|
|
|
+ return $result ? json_show(0, "账户{$message}成功") : json_show(1005, "账户{$message}失败");
|
|
|
}
|
|
|
|
|
|
public function UserListByCompany()
|
|
|
{
|
|
|
- $post=$this->request->only(["nickname"=>"","username"=>"","status"=>"","uid"=>[],"nuid"=>[],"companyNo"=>"","page"=>1, "size"=>10],"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'])&& $post['uid']!==""&&!empty($post['uid']) ? $condition[]=["a.id","in",$post['uid']] : "";
|
|
|
- isset($post['nuid'])&& $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];
|
|
|
+ $post = $this->request->only(["nickname" => "", "username" => "", "status" => "", "uid" => [], "nuid" => [], "companyNo" => "", "page" => 1, "size" => 10], "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']) && $post['uid'] !== "" && !empty($post['uid']) ? $condition[] = ["a.id", "in", $post['uid']] : "";
|
|
|
+ isset($post['nuid']) && $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];
|
|
|
|
|
|
- $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")
|
|
|
- ->leftJoin("account_company c","a.id=c.account_id and c.status=1 and c.is_del=0")
|
|
|
- ->where($condition)->whereOr($whereor)->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")
|
|
|
- ->leftJoin("account_company c","a.id=c.account_id and c.is_del=0")
|
|
|
- ->where($condition)->whereOr($whereor)->page($page,$size)->order("c.addtime desc,a.addtime desc")
|
|
|
- ->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime,c.companyCode,c.companyName,c.is_main,c.status as com_status")
|
|
|
- ->cursor();
|
|
|
- $data=[];
|
|
|
- foreach ($list as $item){
|
|
|
- $item['plat']= Db::name("account_plat")->alias("a")
|
|
|
- ->leftJoin("platform b","a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
|
|
|
- ->where(["a.status"=>1,"a.is_del"=>0,"a.account_id"=>$item['id']])->column("a.plat_code,plat_name");
|
|
|
- $item['company_relaton'] = Db::name("account_company")->where(["account_id"=>$item['id'],"is_del"=>0])
|
|
|
- ->column("companyCode,companyName,company_type,is_main,status");
|
|
|
- $data[]=$item;
|
|
|
+ ->leftJoin("user b", "a.id=b.account_id and b.status=1")
|
|
|
+ ->leftJoin("account_company c", "a.id=c.account_id and c.status=1 and c.is_del=0")
|
|
|
+ ->where($condition)->whereOr($whereor)->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")
|
|
|
+ ->leftJoin("account_company c", "a.id=c.account_id and c.is_del=0")
|
|
|
+ ->where($condition)->whereOr($whereor)->page($page, $size)->order("c.addtime desc,a.addtime desc")
|
|
|
+ ->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime,c.companyCode,c.companyName,c.is_main,c.status as com_status")
|
|
|
+ ->cursor();
|
|
|
+ $data = [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $item['plat'] = Db::name("account_plat")->alias("a")
|
|
|
+ ->leftJoin("platform b", "a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
|
|
|
+ ->where(["a.status" => 1, "a.is_del" => 0, "a.account_id" => $item['id']])->column("a.plat_code,plat_name");
|
|
|
+ $item['company_relaton'] = Db::name("account_company")->where(["account_id" => $item['id'], "is_del" => 0])
|
|
|
+ ->column("companyCode,companyName,company_type,is_main,status");
|
|
|
+ $data[] = $item;
|
|
|
}
|
|
|
|
|
|
- return json_show(0,"获取成功",["list"=>$data,"count"=>$count]);
|
|
|
- }
|
|
|
+ return json_show(0, "获取成功", ["list" => $data, "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){
|
|
|
- if(!empty($post['companyArr'])){
|
|
|
- $company_insert=[];
|
|
|
- $acount =new AccountCompany();
|
|
|
+ $user = Db::table("sys_user")->insert($data);
|
|
|
+ if ($user != false) {
|
|
|
+ if (!empty($post['companyArr'])) {
|
|
|
+ $company_insert = [];
|
|
|
+ $acount = new AccountCompany();
|
|
|
|
|
|
- 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"),
|
|
|
- ];
|
|
|
- }
|
|
|
- $acount->saveAll($company_insert);
|
|
|
- }
|
|
|
- Db::commit();
|
|
|
- return json_show(0,"账户注册成功");
|
|
|
+ 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"),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $acount->saveAll($company_insert);
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return json_show(0, "账户注册成功");
|
|
|
}
|
|
|
}
|
|
|
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());
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //删除
|
|
|
+ public function userDelete()
|
|
|
+ {
|
|
|
+
|
|
|
+ $param = $this->request->only(['ids'], 'post', 'trim');
|
|
|
+
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'ids' => 'require|array|max:100',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (!$val->check($param)) return json_show(1004, $val->getError());
|
|
|
+
|
|
|
+ $rs = Db::name('account')
|
|
|
+ ->where(['is_del' => 0])
|
|
|
+ ->whereIn('id', $param['ids'])
|
|
|
+ ->update([
|
|
|
+ 'is_del' => 1,
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+ return $rs ? json_show(0, '删除成功') : json_show(1004, '删除失败');
|
|
|
+
|
|
|
+ }
|
|
|
}
|