123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792 |
- <?php
- 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;
- 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()
- {
- $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;
- $count = Db::name("account")
- ->alias("a")
- ->leftJoin("user b", "a.id=b.account_id and b.status=1")
- ->where($condition)
- ->count('a.id');
- $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")
- // ->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" => $da['id']])
- // ->field("a.plat_code,plat_name")
- // ->select()
- // ->toArray();
- // })
- ->withAttr('company_relaton', function ($val, $da) {
- return Db::name("account_company")
- ->where(["account_id" => $da['id'], "is_del" => 0])
- ->field("companyCode,companyName,company_type,is_main,status")
- ->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,a.level")
- ->select()
- ->toArray();
- return json_show(0, "获取成功", ["list" => $list, "count" => $count]);
- }
- /** @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 不能为空");
- }
- $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,a.level")
- ->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);
- }
- /**
- * @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, "账户不存在");
- }
- $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 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()
- {
- $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, "账户不存在");
- }
- $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, "手机号已存在!");
- }
- 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) {
- Db::rollback();
- return json_show(1005, $e->getMessage());
- }
- }
- /**
- * @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, "账户不存在");
- }
- if ($account['status'] == $post['status']) {
- return json_show(1004, "数据已更新");
- }
- $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}成功");
- }
- }
- 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,'level' => ''], "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];
- if ($post['level'] !== '') $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;
- $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")
- ->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)
- // ->whereOr($whereor)
- ->page($page, $size)
- ->append(['plat', 'company_relaton'])
- // ->withAttr('plat', function ($val, $da) {
- // return 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" => $da['id']])
- // ->field("a.plat_code,plat_name")
- // ->select()
- // ->toArray();
- // })
- ->withAttr('company_relaton', function ($val, $da) {
- return Db::name("account_company")
- ->where(["account_id" => $da['id'], "is_del" => 0])
- ->field("companyCode,companyName,company_type,is_main,status")
- ->select()
- ->toArray();
- })
- ->order("a.addtime desc")
- ->select()
- ->toArray();
- 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" => [],'level'], "post", "trim");
- $validate = Validate::rule([
- 'nickname|真实姓名' => 'require|min:2|max:200',
- 'mobile|手机号' => 'require|number|length:11|mobile',
- 'email|邮箱' => 'email',
- 'level|账号等级' => 'require|number|in:1,2,3',
- 'companyArr|关联公司' => 'requireIf:level,2|requireIf:level,3|array',
- ]);
- if ($validate->check($post) == false) return json_show(1004, $validate->getError());
- $uiq = Db::table("sys_account")->field('id')->where(["mobile" => $post['mobile']])->find();
- if ($uiq) return json_show(1002, "手机号已注册!");
- Db::startTrans();
- try {
- $date = date('Y-m-d H:i:s');
- $salt = makeSalt();
- $password = sha1("dingding123" . $salt);
- $da = [
- 'username' => $post['mobile'],
- "password" => $password,
- "salt" => $salt,
- "mobile" => $post['mobile'],
- "source" => "paltadd",
- "status" => 1,
- 'level'=>$post['level'],
- "addtime" => $date,
- "updatetime" => $date
- ];
- $reuslt = Db::table('sys_account')->insert($da, 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,
- "updatetime" => $date
- ];
- $user = Db::table("sys_user")->insert($data);
- if ($user != false) {
- $acount = new AccountCompany();
- if (!empty($post['companyArr'])) {
- // //判断关联条件是否都是供应商
- // $all_companyNo = array_column($post['companyArr'], 'companyCode');
- //
- // $tmp = Db::name('headquarters')
- // ->where(['is_del' => 0, 'status' => 1])
- // ->whereFindInSet('type', '1')
- // ->column('code');
- // $temp = array_diff($all_companyNo, $tmp);
- // if (!empty($temp)) throw new Exception(implode(',', $temp) . '不是业务公司');
- $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,
- "updatetime" => $date,
- ];
- }
- $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']]);
- }
- }
- Db::rollback();
- return json_show(1002, "账户注册失败");
- } catch (\Exception $e) {
- Db::rollback();
- return json_show(1002, "账户注册失败," . $e->getMessage());
- }
- }
- //添加超管账号
- // public function addAdminAccount()
- // {
- //
- // $post = $this->request->filter('trim')->post();
- //
- // $tmp = Db::table("sys_account")
- // ->field('id')
- // ->where(["mobile" => $post['mobile'], 'is_del' => 0])
- // ->findOrEmpty();
- // if ($tmp) return json_show(1002, "手机号已注册");
- //
- // Db::startTrans();
- // try {
- // $date = date("Y-m-d H:i:s");
- // $salt = makeSalt();
- // $password = sha1("dingding123" . $salt);
- // $da = [
- // 'username' => $post['mobile'],
- // "password" => $password,
- // "salt" => $salt,
- // "mobile" => $post['mobile'],
- // "source" => "paltadd",
- // "status" => 1,
- // "level" => 1,
- // "addtime" => date("Y-m-d H:i:s"),
- // "updatetime" => date("Y-m-d H:i:s")
- // ];
- // $reuslt = Db::table('sys_account')->insert($da, 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,
- // "updatetime" => $date
- // ];
- // $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,
- // "updatetime" => $date,
- // ];
- // }
- // $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,
- // "updatetime" => $date,
- // ];
- // $u = $acount->save($company_insert);
- // }
- //
- // if ($u == false) throw new Exception("账户新建失败");
- // Db::commit();
- // return json_show(0, "账户注册成功", ["userid" => $reuslt, "nickname" => $post['nickname']]);
- // }
- // }
- // Db::rollback();
- // return json_show(1002, "账户注册失败");
- //
- // } catch (\Exception $e) {
- // Db::rollback();
- // return json_show(1002, "账户注册失败" . $e->getMessage());
- // }
- //
- // }
- //添加供应商账号
- // public function addSupplierAccount()
- // {
- //
- // $post = $this->request->filter('trim')->post();
- //
- // $tmp = Db::table("sys_account")
- // ->field('id')
- // ->where(["mobile" => $post['mobile'], 'is_del' => 0])
- // ->findOrEmpty();
- // if ($tmp) return json_show(1002, "手机号已注册");
- //
- // Db::startTrans();
- //
- // try {
- // $date = date("Y-m-d H:i:s");
- // $salt = makeSalt();
- // $password = sha1("dingding123" . $salt);
- // $da = [
- // 'username' => $post['mobile'],
- // "password" => $password,
- // "salt" => $salt,
- // "mobile" => $post['mobile'],
- // "source" => "paltadd",
- // "status" => 1,
- // "level" => 3,//供应商端账号
- // "addtime" => date("Y-m-d H:i:s"),
- // "updatetime" => date("Y-m-d H:i:s")
- // ];
- // $reuslt = Db::table('sys_account')->insert($da, 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,
- // "updatetime" => $date
- // ];
- // $user = Db::table("sys_user")->insert($data);
- // if ($user != false) {
- //
- // //判断关联条件是否都是供应商
- // $all_companyNo = array_column($post['companyArr'], 'companyCode');
- //
- // $tmp = Db::name('headquarters')
- // ->where(['is_del' => 0, 'status' => 1])
- // ->whereFindInSet('type', '3')
- // ->column('code');
- // $temp = array_diff($all_companyNo, $tmp);
- // if (!empty($temp)) throw new Exception(implode(',', $temp) . '不是供应商');
- //
- // $company_insert = [];
- // foreach ($post['companyArr'] as $company) {
- // $company_insert[] = [
- // "account_id" => $reuslt,
- // "companyCode" => $company['companyCode'],
- // "companyName" => $company['companyName'],
- // "company_type" => 1,
- // "is_main" => $company['is_main'],
- // "status" => 1,
- // "is_del" => 0,
- // "addtime" => $date,
- // "updatetime" => $date,
- // ];
- // }
- //
- // if ($company_insert) Db::name('account_company')->insertAll($company_insert);
- //
- // Db::commit();
- // return json_show(0, "添加供应商账号成功", ["userid" => $reuslt, "nickname" => $post['nickname']]);
- // }
- // }
- // Db::rollback();
- // return json_show(1002, "添加供应商账号失败");
- //
- // } catch (Exception $e) {
- // Db::rollback();
- // return json_show(1002, "添加供应商账号失败," . $e->getMessage());
- // }
- //
- // }
- //修改密码通过旧密码
- public function passSetByPassword()
- {
- $param = $this->request->only(['uid', 'old_pass', 'new_pass'], 'post', 'trim');
- $val = Validate::rule([
- 'uid|用户ID' => 'require|number|gt:0',
- 'old_pass|旧密码' => 'require|max:255',
- 'new_pass|新密码' => 'require|min:6|max:255',
- ]);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- $acc = Db::name("account")
- ->field('id,password,salt,status')
- ->where(['id' => $param['uid'], "is_del" => Account::$account_del])
- ->findOrEmpty();
- if (empty($acc)) return json_show(1003, '账户不存在');
- if ($acc['status'] == Account::$account_end) return json_show(1003, '账户已禁用');
- $sha1 = sha1($param['old_pass'] . $acc['salt']);
- if ($sha1 != $acc['password']) return json_show(1003, '密码错误');
- $salt = makeSalt();
- $password = sha1($param['new_pass'] . $salt);
- $rs = Db::name('account')
- ->where(['id' => $param['uid'], "is_del" => Account::$account_del])
- ->update([
- 'password' => $password,
- 'salt' => $salt,
- 'updatetime' => date('Y-m-d H:i:s')
- ]);
- return $rs ? json_show(0, '修改密码成功') : json_show(1004, '修改密码失败');
- }
- //获取用户所绑定的公司列表
- public function getCompanyList(){
- $post = $this->request->only(["uid" => 0, "companyCode" => "","companyName" => "", "page" => 1, "size" => 20], "post", "trim");
- $where=[['a.is_del','=',0],['a.account_id','=',$post['uid']]];
- if($post['companyCode']!='') $where[]=['a.companyCode','like','%'.$post['companyCode'].'%'];
- if($post['companyName']!='') $where[]=['a.companyName','like','%'.$post['companyName'].'%'];
- $count = Db::name('account_company')
- ->alias('a')
- ->where($where)
- ->count('a.id');
- $list = Db::name('account_company')
- ->alias('a')
- ->field('a.*,b.level')
- ->where($where)
- ->leftJoin('account b','b.id=a.account_id')
- ->order(['a.id' => 'asc'])
- ->page(intval($post['page']), intval($post['size']))
- ->select()
- ->toArray();
- return json_show(0, '获取用户所绑定的公司列表成功', ['count' => $count, 'list' => $list]);
- }
- //所有账号
- public function userAll()
- {
- $post = $this->request->filter('trim')->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']] : "";
- $list = Db::name("account")
- ->field("a.id,a.username,a.mobile,a.status,b.nickname,a.level")
- ->alias("a")
- ->leftJoin("user b", "a.id=b.account_id and b.status=1")
- ->where($condition)
- ->order(['a.id' => 'desc'])
- ->select()
- ->toArray();
- return json_show(0, "获取成功", $list);
- }
- //检查供应商是否有开通账号
- public function checkHasAccountBySupplierNos()
- {
- $supplierNos = $this->request->post('supplierNo', '', 'trim');
- $where = [
- ['a.is_del', '=', 0],
- ['a.status', '=', 1],
- ['b.level', '=', 3],
- ['a.companyCode', 'like', 'QS%']
- ];
- if ($supplierNos !== '') $where[] = ['a.companyCode', 'in', $supplierNos];
- $list = Db::name('account_company')
- ->alias('a')
- ->leftJoin('account b', 'b.id=a.account_id')
- ->where($where)
- ->column('a.account_id', 'a.companyCode');
- return json_show(0, '获取供应商账号开通情况成功', $list);
- }
- }
|