|
@@ -87,7 +87,7 @@ class User extends BaseController
|
|
|
* return app_show($data['code'],$data['message'],$data['data']);
|
|
|
**/
|
|
|
|
|
|
- $param = $this->request->only(['nickname' => '', 'username' => '', 'status' => '', 'page' => 1, 'size' => 10,'uid'=>'','nuid'=>''], 'post','trim');
|
|
|
+ $param = $this->request->only(['nickname' => '', 'username' => '', 'status' => '', 'page' => 1, 'size' => 10, 'uid' => '', 'nuid' => ''], 'post', 'trim');
|
|
|
|
|
|
$userCommon = new CommonUser();
|
|
|
$rs = $userCommon->GetUserlist($param);
|
|
@@ -98,16 +98,17 @@ class User extends BaseController
|
|
|
}
|
|
|
|
|
|
//删除
|
|
|
- public function delete(){
|
|
|
- $param = $this->request->only(['ids'], 'post','trim');
|
|
|
+ public function delete()
|
|
|
+ {
|
|
|
+ $param = $this->request->only(['ids'], 'post', 'trim');
|
|
|
|
|
|
- $val=Validate::rule([
|
|
|
- 'ids'=>'require|array|max:100',
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'ids' => 'require|array|max:100',
|
|
|
]);
|
|
|
|
|
|
- if(!$val->check($param)) return json_show(1004,$val->getError());
|
|
|
+ if (!$val->check($param)) return json_show(1004, $val->getError());
|
|
|
|
|
|
- if(in_array($this->uid,$param['ids'])) return json_show(1004,'自己不能删除自己');
|
|
|
+ if (in_array($this->uid, $param['ids'])) return json_show(1004, '自己不能删除自己');
|
|
|
|
|
|
$userCommon = new CommonUser();
|
|
|
$rs = $userCommon->userDelete($param);
|
|
@@ -116,80 +117,86 @@ class User extends BaseController
|
|
|
return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param token
|
|
|
- * @return \think\response\Json
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
+ //详情
|
|
|
public function userInfo()
|
|
|
{
|
|
|
- $post = $this->request->post();
|
|
|
- $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
- if ($token == "") {
|
|
|
- return app_show(101, 'token不能为空');
|
|
|
- }
|
|
|
- $effetc = VerifyTokens($token);
|
|
|
- if (!empty($effetc) && $effetc['code'] != 0) {
|
|
|
- return app_show($effetc['code'], $effetc['message']);
|
|
|
- }
|
|
|
- $userinfo = GetUserInfo($token);
|
|
|
- if (empty($userinfo) || $userinfo['code'] != 0) {
|
|
|
- return app_show(102, "员工信息不存在");
|
|
|
- }
|
|
|
- $id = isset($post['id']) && $post['id'] !== "" ? trim($post['id']) : "";
|
|
|
- if ($id == "") {
|
|
|
- return error_show(1004, "id不能为空");
|
|
|
- }
|
|
|
- $to = GetInfoById($token, ['id' => $id]);
|
|
|
- if (empty($to) || $to['code'] != 0) {
|
|
|
- return app_show(1002, "员工信息不存在");
|
|
|
- }
|
|
|
- // $nickname = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
|
|
|
- $data = $to['data'];
|
|
|
- $role = Db::name("user_role")->alias('a')->leftJoin('role b', "a.roleid = b.id")->where("a.uid", "=", $data['id'])
|
|
|
- ->field("roleid,role_name,business_all,uid,a.status")->find();
|
|
|
- $data['role_name'] = isset($role['role_name']) ? $role['role_name'] : "";
|
|
|
- $data['roleid'] = isset($role['roleid']) ? $role['roleid'] : "";
|
|
|
- $data['status'] = isset($role['status']) ? $role['status'] : '0';
|
|
|
- $st = Db::name('user_business')->where(['userid' => $role['uid'], "is_del" => 0])->field('businessid,is_main')->select()->toArray();
|
|
|
- $val = [];
|
|
|
- if (!empty($st)) {
|
|
|
- foreach ($st as $itom) {
|
|
|
- $tep = [];
|
|
|
- $business = Db::name('business')->where(['id' => $itom['businessid'], "is_del" => 0])->field("company,companyNo")->find();
|
|
|
- $tep['company'] = isset($business['company']) ? $business['company'] : "";
|
|
|
- $tep['companyNo'] = isset($business['companyNo']) ? $business['companyNo'] : "";
|
|
|
- $tep['businessid'] = $itom['businessid'];
|
|
|
- $tep['is_main'] = $itom['is_main'];
|
|
|
- $val[] = $tep;
|
|
|
- }
|
|
|
- }
|
|
|
- $data['business'] = $val;
|
|
|
- $info = [];
|
|
|
- $stn = Db::name('user_platform')->where(['uid' => $role['uid']])->find();
|
|
|
- if ($stn != false) {
|
|
|
- $plat = isset($stn['platform']) ? explode(",", $stn['platform']) : "";
|
|
|
- if ($plat != "") {
|
|
|
- $platform = Db::name('platform')->where(['id' => $plat, 'is_del' => 0])->column("id,platform_name,platform_code");
|
|
|
- $info = $platform;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * $post = $this->request->post();
|
|
|
+ * $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ * if ($token == "") {
|
|
|
+ * return app_show(101, 'token不能为空');
|
|
|
+ * }
|
|
|
+ * $effetc = VerifyTokens($token);
|
|
|
+ * if (!empty($effetc) && $effetc['code'] != 0) {
|
|
|
+ * return app_show($effetc['code'], $effetc['message']);
|
|
|
+ * }
|
|
|
+ * $userinfo = GetUserInfo($token);
|
|
|
+ * if (empty($userinfo) || $userinfo['code'] != 0) {
|
|
|
+ * return app_show(102, "员工信息不存在");
|
|
|
+ * }
|
|
|
+ * $id = isset($post['id']) && $post['id'] !== "" ? trim($post['id']) : "";
|
|
|
+ * if ($id == "") {
|
|
|
+ * return error_show(1004, "id不能为空");
|
|
|
+ * }
|
|
|
+ * $to = GetInfoById($token, ['id' => $id]);
|
|
|
+ * if (empty($to) || $to['code'] != 0) {
|
|
|
+ * return app_show(1002, "员工信息不存在");
|
|
|
+ * }
|
|
|
+ * // $nickname = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
|
|
|
+ * $data = $to['data'];
|
|
|
+ * $role = Db::name("user_role")->alias('a')->leftJoin('role b', "a.roleid = b.id")->where("a.uid", "=", $data['id'])
|
|
|
+ * ->field("roleid,role_name,business_all,uid,a.status")->find();
|
|
|
+ * $data['role_name'] = isset($role['role_name']) ? $role['role_name'] : "";
|
|
|
+ * $data['roleid'] = isset($role['roleid']) ? $role['roleid'] : "";
|
|
|
+ * $data['status'] = isset($role['status']) ? $role['status'] : '0';
|
|
|
+ * $st = Db::name('user_business')->where(['userid' => $role['uid'], "is_del" => 0])->field('businessid,is_main')->select()->toArray();
|
|
|
+ * $val = [];
|
|
|
+ * if (!empty($st)) {
|
|
|
+ * foreach ($st as $itom) {
|
|
|
+ * $tep = [];
|
|
|
+ * $business = Db::name('business')->where(['id' => $itom['businessid'], "is_del" => 0])->field("company,companyNo")->find();
|
|
|
+ * $tep['company'] = isset($business['company']) ? $business['company'] : "";
|
|
|
+ * $tep['companyNo'] = isset($business['companyNo']) ? $business['companyNo'] : "";
|
|
|
+ * $tep['businessid'] = $itom['businessid'];
|
|
|
+ * $tep['is_main'] = $itom['is_main'];
|
|
|
+ * $val[] = $tep;
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * $data['business'] = $val;
|
|
|
+ * $info = [];
|
|
|
+ * $stn = Db::name('user_platform')->where(['uid' => $role['uid']])->find();
|
|
|
+ * if ($stn != false) {
|
|
|
+ * $plat = isset($stn['platform']) ? explode(",", $stn['platform']) : "";
|
|
|
+ * if ($plat != "") {
|
|
|
+ * $platform = Db::name('platform')->where(['id' => $plat, 'is_del' => 0])->column("id,platform_name,platform_code");
|
|
|
+ * $info = $platform;
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * }
|
|
|
+ * $depart = Db::name("depart_user")->where([["uid", "=", $data['id']], ["is_del", "=", 0]])->column("itemid");
|
|
|
+ * $data['depart'] = "";
|
|
|
+ *
|
|
|
+ * if (!empty($depart)) {
|
|
|
+ * $deparname = Db::name("company_item")->where(["id" => $depart, "is_del" => 0])->field("id,name,depart_link")->select()->toArray();
|
|
|
+ * if (!empty($deparname)) {
|
|
|
+ * foreach ($deparname as $ky => $item) {
|
|
|
+ * $deparname[$ky]['depart_code'] = array_filter(explode("-", $item['depart_link']));
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * $data['depart'] = $deparname;
|
|
|
+ * }
|
|
|
+ * $data['platform'] = $info;
|
|
|
+ *
|
|
|
+ * return app_show(0, "获取成功", $data);
|
|
|
+ * **/
|
|
|
|
|
|
- }
|
|
|
- $depart = Db::name("depart_user")->where([["uid", "=", $data['id']], ["is_del", "=", 0]])->column("itemid");
|
|
|
- $data['depart'] = "";
|
|
|
+ $id = $this->request->post('id/d', 0, "trim");
|
|
|
|
|
|
- if (!empty($depart)) {
|
|
|
- $deparname = Db::name("company_item")->where(["id" => $depart, "is_del" => 0])->field("id,name,depart_link")->select()->toArray();
|
|
|
- if (!empty($deparname)) {
|
|
|
- foreach ($deparname as $ky => $item) {
|
|
|
- $deparname[$ky]['depart_code'] = array_filter(explode("-", $item['depart_link']));
|
|
|
- }
|
|
|
- }
|
|
|
- $data['depart'] = $deparname;
|
|
|
- }
|
|
|
- $data['platform'] = $info;
|
|
|
+ $userCommon = new CommonUser();
|
|
|
+ $rs = json_decode($userCommon->GetUserInfo(['id' => $id]), true);
|
|
|
+
|
|
|
+ return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
|
|
|
- return app_show(0, "获取成功", $data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -373,274 +380,316 @@ class User extends BaseController
|
|
|
return $insert ? app_show(0, '数据新建成功') : error_show(1004, '数据新建失败');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 保存新建的资源
|
|
|
- *
|
|
|
- * @param \think\Request $request
|
|
|
- * @return \think\Response
|
|
|
- */
|
|
|
+ //修改
|
|
|
public function UserSave()
|
|
|
{
|
|
|
- $post = $this->request->post();
|
|
|
- $toke = isset($post['token']) ? trim($post['token']) : "";
|
|
|
- if ($toke == "") {
|
|
|
- return app_show(100, "token不能为空");
|
|
|
- }
|
|
|
- $verify = VerifyTokens($toke);
|
|
|
- if ($verify['code'] != 0) {
|
|
|
- return app_show($verify['code'], $verify['message']);
|
|
|
- }
|
|
|
- $userid = isset($post['id']) && $post['id'] !== "" ? intval($post['id']) : "";
|
|
|
- if ($userid == "") {
|
|
|
- return error_show(1004, "参数id 不能为空");
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * $post = $this->request->post();
|
|
|
+ * $toke = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ * if ($toke == "") {
|
|
|
+ * return app_show(100, "token不能为空");
|
|
|
+ * }
|
|
|
+ * $verify = VerifyTokens($toke);
|
|
|
+ * if ($verify['code'] != 0) {
|
|
|
+ * return app_show($verify['code'], $verify['message']);
|
|
|
+ * }
|
|
|
+ * $userid = isset($post['id']) && $post['id'] !== "" ? intval($post['id']) : "";
|
|
|
+ * if ($userid == "") {
|
|
|
+ * return error_show(1004, "参数id 不能为空");
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * $nickname = isset($post['nickname']) ? trim($post['nickname']) : "";
|
|
|
+ * if ($nickname == "") {
|
|
|
+ * return app_show(1001, "昵称不能为空");
|
|
|
+ * }
|
|
|
+ * $mobile = isset($post['mobile']) ? trim($post['mobile']) : "";
|
|
|
+ * if ($mobile == "") {
|
|
|
+ * return app_show(1002, "手机号不能为空");
|
|
|
+ * }
|
|
|
+ * if (checkMobile($mobile) == false) {
|
|
|
+ * return app_show(1002, "手机号格式不正确");
|
|
|
+ * }
|
|
|
+ * $email = isset($post['email']) ? trim($post['email']) : "";
|
|
|
+ * $role = isset($post['role']) ? intval($post['role']) : 0;
|
|
|
+ * if ($role != 0) {
|
|
|
+ * $roleinfo = Db::name("role")->where("id", "=", $role)->find();
|
|
|
+ * if (empty($roleinfo)) {
|
|
|
+ * return error_show(1002, "角色不存在");
|
|
|
+ * }
|
|
|
+ * if ($roleinfo['status'] == 0) {
|
|
|
+ * return error_show(1002, "角色已禁用");
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * $itemid = isset($post['itemid']) && $post['itemid'] !== "" ? $post['itemid'] : "";
|
|
|
+ * $item_arr = [];
|
|
|
+ * if ($itemid !== "") {
|
|
|
+ * foreach ($itemid as $value) {
|
|
|
+ * $item_arr[] = end($value);
|
|
|
+ * }
|
|
|
+ * $iteminfo = Db::name("company_item")->where(["id" => $item_arr, 'is_del' => 0])->select()->toArray();
|
|
|
+ * if (empty($iteminfo)) {
|
|
|
+ * return error_show(1002, "未找到部门信息");
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * $companyArr = isset($post['companyArr']) && !empty($post['companyArr']) ? $post['companyArr'] : "";
|
|
|
+ * if ($companyArr == "") {
|
|
|
+ * return error_show(1004, "参数companyArr不能为空");
|
|
|
+ * }
|
|
|
+ * $compArr = [];
|
|
|
+ * foreach ($companyArr as $value) {
|
|
|
+ * $tmp = [];
|
|
|
+ * if (!isset($value['businessid']) || $value['businessid'] == '') {
|
|
|
+ * return error_show(1004, "参数业务公司businessid不能为空");
|
|
|
+ * }
|
|
|
+ * $tmp['userid'] = $userid;
|
|
|
+ * $tmp['businessid'] = $value['businessid'];
|
|
|
+ * $tmp['is_main'] = isset($value['is_main']) ? $value['is_main'] : 0;
|
|
|
+ * $tmp['is_del'] = 0;
|
|
|
+ * $tmp['addtime'] = date("Y-m-d H:i:s");
|
|
|
+ * $tmp['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ * $compArr[] = $tmp;
|
|
|
+ * }
|
|
|
+ * $platform = isset($post['platform']) && !empty($post['platform']) ? $post['platform'] : "";
|
|
|
+ * if ($platform == "") {
|
|
|
+ * return error_show(1004, "参数platform不能为空");
|
|
|
+ * }
|
|
|
+ * $plta = Db::name("platform")->where(["id" => $platform, "is_del" => 0])->select()->toArray();
|
|
|
+ * if (empty($plta)) {
|
|
|
+ * return error_show(1004, "未找到可用平台");
|
|
|
+ * }
|
|
|
+ * $userplat = Db::name("user_platform")->where(["uid" => $userid, "is_del" => 0])->find();
|
|
|
+ *
|
|
|
+ * $isall = isset($post['is_all']) && $post['is_all'] !== "" ? intval($post['is_all']) : "0";
|
|
|
+ *
|
|
|
+ * Db::startTrans();
|
|
|
+ * try {
|
|
|
+ * $sc = Db::name("user_business")->where(["userid" => $userid, "is_del" => 0])->select()->toArray();
|
|
|
+ * if (!empty($sc)) {
|
|
|
+ * $del = Db::name("user_business")->where(["userid" => $userid, "is_del" => 0])->save(["is_del" => 1,
|
|
|
+ * "updatetime" => date("Y-m-d H:i:s")]);
|
|
|
+ * if ($del == false) {
|
|
|
+ * Db::rollback();
|
|
|
+ * return error_show(1005, '业务公司添加失败');
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * if (!empty($compArr)) {
|
|
|
+ * $in = Db::name("user_business")->insertAll($compArr);
|
|
|
+ * if ($in == 0) {
|
|
|
+ * Db::rollback();
|
|
|
+ * return error_show(1005, '业务公司添加失败');
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * if ($userplat == false) {
|
|
|
+ * $userplat = [
|
|
|
+ * "uid" => $userid,
|
|
|
+ * "platform" => implode(",", $platform),
|
|
|
+ * "is_del" => 0,
|
|
|
+ * "addtime" => date("Y-m-d H:i:s"),
|
|
|
+ * "updatetime" => date("Y-m-d H:i:s")
|
|
|
+ * ];
|
|
|
+ * } else {
|
|
|
+ * $userplat['platform'] = implode(",", $platform);
|
|
|
+ * $userplat['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ * }
|
|
|
+ * $patup = Db::name("user_platform")->save($userplat);
|
|
|
+ * if ($patup == false) {
|
|
|
+ * Db::rollback();
|
|
|
+ * return error_show(1005, '业务平台添加失败');
|
|
|
+ * }
|
|
|
+ * $userrole = Db::name("user_role")->where(["uid" => $userid, "is_del" => 0])->find();
|
|
|
+ * if (empty($userrole)) {
|
|
|
+ * $roledata = [
|
|
|
+ * "uid" => $userid,
|
|
|
+ * "roleid" => $role,
|
|
|
+ * "status" => 1,
|
|
|
+ * "business_all" => $isall,
|
|
|
+ * "addtime" => date("Y-m-d H:i:s"),
|
|
|
+ * "updatetime" => date("Y-m-d H:i:s")
|
|
|
+ * ];
|
|
|
+ * $up = Db::name("user_role")->insert($roledata);
|
|
|
+ * } else {
|
|
|
+ * $userrole['roleid'] = $role;
|
|
|
+ * $userrole['business_all'] = $isall;
|
|
|
+ * $userrole['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ * $up = Db::name("user_role")->save($userrole);
|
|
|
+ * }
|
|
|
+ * if ($up) {
|
|
|
+ * Db::name("depart_user")->where(["uid" => $userid])->save(['is_del' => 1]);
|
|
|
+ * if (isset($item_arr) && !empty($item_arr)) {
|
|
|
+ * foreach ($item_arr as $v) {
|
|
|
+ * $depin = [
|
|
|
+ * "uid" => $userid,
|
|
|
+ * "nickname" => $nickname,
|
|
|
+ * "itemid" => $v,
|
|
|
+ * "is_del" => 0,
|
|
|
+ * "updatetime" => date("Y-m-d H:i:s")
|
|
|
+ * ];
|
|
|
+ * $ist = Db::name("depart_user")->where(["uid" => $userid, "itemid" => $v])->find();
|
|
|
+ * if ($ist) {
|
|
|
+ * $up = Db::name("depart_user")->where(["uid" => $userid, "itemid" => $v])->save($depin);
|
|
|
+ * } else {
|
|
|
+ * $depin['addtime'] = date("Y-m-d H:i:s");
|
|
|
+ * $up = Db::name("depart_user")->insert($depin);
|
|
|
+ * }
|
|
|
+ * if ($up == false) {
|
|
|
+ * Db::rollback();
|
|
|
+ * return error_show(1005, '用户部门更新失败');
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * } else {
|
|
|
+ * Db::rollback();
|
|
|
+ * return error_show(1005, '角色更新失败');
|
|
|
+ * }
|
|
|
+ * $data = [
|
|
|
+ * "id" => $userid,
|
|
|
+ * "nickname" => $nickname,
|
|
|
+ * "mobile" => $mobile,
|
|
|
+ * "email" => $email
|
|
|
+ * ];
|
|
|
+ * $save = resetinfo($toke, $data);
|
|
|
+ * if (!empty($save) && $save['code'] != 0) {
|
|
|
+ * Db::rollback();
|
|
|
+ * return error_show($save['code'], $save['message']);
|
|
|
+ * }
|
|
|
+ * Db::commit();
|
|
|
+ * return app_show(0, "更新成功");
|
|
|
+ * } catch (\Exception $e) {
|
|
|
+ * Db::rollback();
|
|
|
+ * return app_show(1002, $e->getMessage());
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * **/
|
|
|
+
|
|
|
+ $post = $this->request->only(["id", "nickname", "mobile", "email" => "", "portrait" => "", "sex" => ""], "post", 'trim');
|
|
|
+ $validate = Validate::rule([
|
|
|
+ 'id|主键ID' => 'require|number|gt:0',
|
|
|
+ 'nickname|名称' => 'require|max:255',
|
|
|
+ 'mobile|手机号' => 'require|mobile',
|
|
|
+ 'email|名称' => 'email',
|
|
|
+ 'sex|性别' => 'number|in:0,1,2',
|
|
|
+ ]);
|
|
|
+ if ($validate->check($post) == false) return json_show(1004, $validate->getError());
|
|
|
|
|
|
- $nickname = isset($post['nickname']) ? trim($post['nickname']) : "";
|
|
|
- if ($nickname == "") {
|
|
|
- return app_show(1001, "昵称不能为空");
|
|
|
- }
|
|
|
- $mobile = isset($post['mobile']) ? trim($post['mobile']) : "";
|
|
|
- if ($mobile == "") {
|
|
|
- return app_show(1002, "手机号不能为空");
|
|
|
- }
|
|
|
- if (checkMobile($mobile) == false) {
|
|
|
- return app_show(1002, "手机号格式不正确");
|
|
|
- }
|
|
|
- $email = isset($post['email']) ? trim($post['email']) : "";
|
|
|
- $role = isset($post['role']) ? intval($post['role']) : 0;
|
|
|
- if ($role != 0) {
|
|
|
- $roleinfo = Db::name("role")->where("id", "=", $role)->find();
|
|
|
- if (empty($roleinfo)) {
|
|
|
- return error_show(1002, "角色不存在");
|
|
|
- }
|
|
|
- if ($roleinfo['status'] == 0) {
|
|
|
- return error_show(1002, "角色已禁用");
|
|
|
- }
|
|
|
- }
|
|
|
- $itemid = isset($post['itemid']) && $post['itemid'] !== "" ? $post['itemid'] : "";
|
|
|
- $item_arr = [];
|
|
|
- if ($itemid !== "") {
|
|
|
- foreach ($itemid as $value) {
|
|
|
- $item_arr[] = end($value);
|
|
|
- }
|
|
|
- $iteminfo = Db::name("company_item")->where(["id" => $item_arr, 'is_del' => 0])->select()->toArray();
|
|
|
- if (empty($iteminfo)) {
|
|
|
- return error_show(1002, "未找到部门信息");
|
|
|
- }
|
|
|
- }
|
|
|
- $companyArr = isset($post['companyArr']) && !empty($post['companyArr']) ? $post['companyArr'] : "";
|
|
|
- if ($companyArr == "") {
|
|
|
- return error_show(1004, "参数companyArr不能为空");
|
|
|
- }
|
|
|
- $compArr = [];
|
|
|
- foreach ($companyArr as $value) {
|
|
|
- $tmp = [];
|
|
|
- if (!isset($value['businessid']) || $value['businessid'] == '') {
|
|
|
- return error_show(1004, "参数业务公司businessid不能为空");
|
|
|
- }
|
|
|
- $tmp['userid'] = $userid;
|
|
|
- $tmp['businessid'] = $value['businessid'];
|
|
|
- $tmp['is_main'] = isset($value['is_main']) ? $value['is_main'] : 0;
|
|
|
- $tmp['is_del'] = 0;
|
|
|
- $tmp['addtime'] = date("Y-m-d H:i:s");
|
|
|
- $tmp['updatetime'] = date("Y-m-d H:i:s");
|
|
|
- $compArr[] = $tmp;
|
|
|
- }
|
|
|
- $platform = isset($post['platform']) && !empty($post['platform']) ? $post['platform'] : "";
|
|
|
- if ($platform == "") {
|
|
|
- return error_show(1004, "参数platform不能为空");
|
|
|
- }
|
|
|
- $plta = Db::name("platform")->where(["id" => $platform, "is_del" => 0])->select()->toArray();
|
|
|
- if (empty($plta)) {
|
|
|
- return error_show(1004, "未找到可用平台");
|
|
|
- }
|
|
|
- $userplat = Db::name("user_platform")->where(["uid" => $userid, "is_del" => 0])->find();
|
|
|
-
|
|
|
- $isall = isset($post['is_all']) && $post['is_all'] !== "" ? intval($post['is_all']) : "0";
|
|
|
-
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- $sc = Db::name("user_business")->where(["userid" => $userid, "is_del" => 0])->select()->toArray();
|
|
|
- if (!empty($sc)) {
|
|
|
- $del = Db::name("user_business")->where(["userid" => $userid, "is_del" => 0])->save(["is_del" => 1,
|
|
|
- "updatetime" => date("Y-m-d H:i:s")]);
|
|
|
- if ($del == false) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1005, '业务公司添加失败');
|
|
|
- }
|
|
|
- }
|
|
|
- if (!empty($compArr)) {
|
|
|
- $in = Db::name("user_business")->insertAll($compArr);
|
|
|
- if ($in == 0) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1005, '业务公司添加失败');
|
|
|
- }
|
|
|
- }
|
|
|
+ $userCommon = new CommonUser();
|
|
|
+ $rs = json_decode($userCommon->userSave($post), true);
|
|
|
|
|
|
- if ($userplat == false) {
|
|
|
- $userplat = [
|
|
|
- "uid" => $userid,
|
|
|
- "platform" => implode(",", $platform),
|
|
|
- "is_del" => 0,
|
|
|
- "addtime" => date("Y-m-d H:i:s"),
|
|
|
- "updatetime" => date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- } else {
|
|
|
- $userplat['platform'] = implode(",", $platform);
|
|
|
- $userplat['updatetime'] = date("Y-m-d H:i:s");
|
|
|
- }
|
|
|
- $patup = Db::name("user_platform")->save($userplat);
|
|
|
- if ($patup == false) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1005, '业务平台添加失败');
|
|
|
- }
|
|
|
- $userrole = Db::name("user_role")->where(["uid" => $userid, "is_del" => 0])->find();
|
|
|
- if (empty($userrole)) {
|
|
|
- $roledata = [
|
|
|
- "uid" => $userid,
|
|
|
- "roleid" => $role,
|
|
|
- "status" => 1,
|
|
|
- "business_all" => $isall,
|
|
|
- "addtime" => date("Y-m-d H:i:s"),
|
|
|
- "updatetime" => date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- $up = Db::name("user_role")->insert($roledata);
|
|
|
- } else {
|
|
|
- $userrole['roleid'] = $role;
|
|
|
- $userrole['business_all'] = $isall;
|
|
|
- $userrole['updatetime'] = date("Y-m-d H:i:s");
|
|
|
- $up = Db::name("user_role")->save($userrole);
|
|
|
- }
|
|
|
- if ($up) {
|
|
|
- Db::name("depart_user")->where(["uid" => $userid])->save(['is_del' => 1]);
|
|
|
- if (isset($item_arr) && !empty($item_arr)) {
|
|
|
- foreach ($item_arr as $v) {
|
|
|
- $depin = [
|
|
|
- "uid" => $userid,
|
|
|
- "nickname" => $nickname,
|
|
|
- "itemid" => $v,
|
|
|
- "is_del" => 0,
|
|
|
- "updatetime" => date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- $ist = Db::name("depart_user")->where(["uid" => $userid, "itemid" => $v])->find();
|
|
|
- if ($ist) {
|
|
|
- $up = Db::name("depart_user")->where(["uid" => $userid, "itemid" => $v])->save($depin);
|
|
|
- } else {
|
|
|
- $depin['addtime'] = date("Y-m-d H:i:s");
|
|
|
- $up = Db::name("depart_user")->insert($depin);
|
|
|
- }
|
|
|
- if ($up == false) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1005, '用户部门更新失败');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1005, '角色更新失败');
|
|
|
- }
|
|
|
- $data = [
|
|
|
- "id" => $userid,
|
|
|
- "nickname" => $nickname,
|
|
|
- "mobile" => $mobile,
|
|
|
- "email" => $email
|
|
|
- ];
|
|
|
- $save = resetinfo($toke, $data);
|
|
|
- if (!empty($save) && $save['code'] != 0) {
|
|
|
- Db::rollback();
|
|
|
- return error_show($save['code'], $save['message']);
|
|
|
- }
|
|
|
- Db::commit();
|
|
|
- return app_show(0, "更新成功");
|
|
|
- } catch (\Exception $e) {
|
|
|
- Db::rollback();
|
|
|
- return app_show(1002, $e->getMessage());
|
|
|
- }
|
|
|
+ return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
}
|
|
|
|
|
|
+ //修改密码
|
|
|
public function setPwd()
|
|
|
{
|
|
|
- $post = $this->request->post();
|
|
|
- $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
- if ($token == "") {
|
|
|
- return error_show(101, 'token不能为空');
|
|
|
- }
|
|
|
- $effetc = VerifyTokens($token);
|
|
|
- if (!empty($effetc) && $effetc['code'] != 0) {
|
|
|
- return error_show($effetc['code'], $effetc['message']);
|
|
|
- }
|
|
|
- $userid = isset($post['id']) && $post['id'] !== "" ? intval($post['id']) : "";
|
|
|
- if ($userid == "") {
|
|
|
- return error_show(1004, "参数id 不能为空");
|
|
|
- }
|
|
|
- $newPwd = isset($post['password']) ? trim($post['password']) : "";
|
|
|
- if ($newPwd == "") {
|
|
|
- return error_show(1001, '密码不能为空');
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * $post = $this->request->post();
|
|
|
+ * $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ * if ($token == "") {
|
|
|
+ * return error_show(101, 'token不能为空');
|
|
|
+ * }
|
|
|
+ * $effetc = VerifyTokens($token);
|
|
|
+ * if (!empty($effetc) && $effetc['code'] != 0) {
|
|
|
+ * return error_show($effetc['code'], $effetc['message']);
|
|
|
+ * }
|
|
|
+ * $userid = isset($post['id']) && $post['id'] !== "" ? intval($post['id']) : "";
|
|
|
+ * if ($userid == "") {
|
|
|
+ * return error_show(1004, "参数id 不能为空");
|
|
|
+ * }
|
|
|
+ * $newPwd = isset($post['password']) ? trim($post['password']) : "";
|
|
|
+ * if ($newPwd == "") {
|
|
|
+ * return error_show(1001, '密码不能为空');
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * $data = resetpwd($token, ["id" => $userid, 'password' => $newPwd]);
|
|
|
+ * if (empty($data) || $data['code'] != 0) {
|
|
|
+ * return error_show($data['code'], $data['message']);
|
|
|
+ * } else {
|
|
|
+ * return app_show(0, "密码修改成功");
|
|
|
+ * }
|
|
|
+ * **/
|
|
|
+ $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)) return json_show(1004, $validate->getError());
|
|
|
|
|
|
- $data = resetpwd($token, ["id" => $userid, 'password' => $newPwd]);
|
|
|
- if (empty($data) || $data['code'] != 0) {
|
|
|
- return error_show($data['code'], $data['message']);
|
|
|
- } else {
|
|
|
- return app_show(0, "密码修改成功");
|
|
|
- }
|
|
|
+ $userCommon = new CommonUser();
|
|
|
+ $rs = json_decode($userCommon->resetPasswd($post), true);
|
|
|
+
|
|
|
+ return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
}
|
|
|
|
|
|
- public function UserStatus()
|
|
|
+ //启禁用
|
|
|
+ public function userStatus()
|
|
|
{
|
|
|
- $post = $this->request->post();
|
|
|
- $toke = isset($post['token']) ? trim($post['token']) : "";
|
|
|
- if ($toke == "") {
|
|
|
- return app_show(100, "token不能为空");
|
|
|
- }
|
|
|
- $verify = VerifyTokens($toke);
|
|
|
- if ($verify['code'] != 0) {
|
|
|
- return app_show($verify['code'], $verify['message']);
|
|
|
- }
|
|
|
- $userid = isset($post['id']) && $post['id'] !== "" ? intval($post['id']) : "";
|
|
|
- if ($userid == "") {
|
|
|
- return error_show(1004, "参数userid 不能为空");
|
|
|
- }
|
|
|
- $status = isset($post['status']) && $post['status'] != "" ? intval($post['status']) : "";
|
|
|
-
|
|
|
- if ($status === "") {
|
|
|
- return error_show(1004, "参数status 不能为空");
|
|
|
- }
|
|
|
- if (!in_array($status, [0, 1])) {
|
|
|
- return error_show(1004, "参数status无效");
|
|
|
- }
|
|
|
- $message = $status == 1 ? "启用" : "禁用";
|
|
|
- $userinfo = Db::name("user_role")->where(["uid" => $userid, "is_del" => 0])->find();
|
|
|
- if ($userinfo == false) {
|
|
|
- $data = [
|
|
|
- "uid" => $userid,
|
|
|
- "roleid" => 0,
|
|
|
- "status" => $status,
|
|
|
- "is_del" => 0,
|
|
|
- "addtime" => date("Y-m-d H:i:s"),
|
|
|
- "updatetime" => date("Y-m-d H:i:s"),
|
|
|
- ];
|
|
|
- $sa = Db::name("user_role")->save($data);
|
|
|
- } else {
|
|
|
- $userinfo['status'] = $status;
|
|
|
- $userinfo['updatetime'] = date("Y-m-d H:i:s");
|
|
|
- $sa = Db::name("user_role")->save($userinfo);
|
|
|
- }
|
|
|
- if ($sa == false) {
|
|
|
- return error_show(1005, "{$message}失败");
|
|
|
- } else {
|
|
|
+ /**
|
|
|
+ * $post = $this->request->post();
|
|
|
+ * $toke = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ * if ($toke == "") {
|
|
|
+ * return app_show(100, "token不能为空");
|
|
|
+ * }
|
|
|
+ * $verify = VerifyTokens($toke);
|
|
|
+ * if ($verify['code'] != 0) {
|
|
|
+ * return app_show($verify['code'], $verify['message']);
|
|
|
+ * }
|
|
|
+ * $userid = isset($post['id']) && $post['id'] !== "" ? intval($post['id']) : "";
|
|
|
+ * if ($userid == "") {
|
|
|
+ * return error_show(1004, "参数userid 不能为空");
|
|
|
+ * }
|
|
|
+ * $status = isset($post['status']) && $post['status'] != "" ? intval($post['status']) : "";
|
|
|
+ *
|
|
|
+ * if ($status === "") {
|
|
|
+ * return error_show(1004, "参数status 不能为空");
|
|
|
+ * }
|
|
|
+ * if (!in_array($status, [0, 1])) {
|
|
|
+ * return error_show(1004, "参数status无效");
|
|
|
+ * }
|
|
|
+ * $message = $status == 1 ? "启用" : "禁用";
|
|
|
+ * $userinfo = Db::name("user_role")->where(["uid" => $userid, "is_del" => 0])->find();
|
|
|
+ * if ($userinfo == false) {
|
|
|
+ * $data = [
|
|
|
+ * "uid" => $userid,
|
|
|
+ * "roleid" => 0,
|
|
|
+ * "status" => $status,
|
|
|
+ * "is_del" => 0,
|
|
|
+ * "addtime" => date("Y-m-d H:i:s"),
|
|
|
+ * "updatetime" => date("Y-m-d H:i:s"),
|
|
|
+ * ];
|
|
|
+ * $sa = Db::name("user_role")->save($data);
|
|
|
+ * } else {
|
|
|
+ * $userinfo['status'] = $status;
|
|
|
+ * $userinfo['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ * $sa = Db::name("user_role")->save($userinfo);
|
|
|
+ * }
|
|
|
+ * if ($sa == false) {
|
|
|
+ * return error_show(1005, "{$message}失败");
|
|
|
+ * } else {
|
|
|
+ *
|
|
|
+ * return app_show(0, "{$message}成功");
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * // $set = resetstatus($toke,["id"=>$userid,"status"=>$status]);
|
|
|
+ * //
|
|
|
+ * // if(empty($set)||$set['code']!=0){
|
|
|
+ * // return error_show(1005,"{$message}失败");
|
|
|
+ * // }else{
|
|
|
+ * // D
|
|
|
+ * // return app_show(0,"{$message}成功");
|
|
|
+ * // }
|
|
|
+ * **/
|
|
|
+
|
|
|
+ $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)) return json_show(1004, $validate->getError());
|
|
|
|
|
|
- return app_show(0, "{$message}成功");
|
|
|
- }
|
|
|
+ $userCommon = new CommonUser();
|
|
|
+ $rs = json_decode($userCommon->resetState($post), true);
|
|
|
|
|
|
-// $set = resetstatus($toke,["id"=>$userid,"status"=>$status]);
|
|
|
-//
|
|
|
-// if(empty($set)||$set['code']!=0){
|
|
|
-// return error_show(1005,"{$message}失败");
|
|
|
-// }else{
|
|
|
-// D
|
|
|
-// return app_show(0,"{$message}成功");
|
|
|
-// }
|
|
|
+ return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
}
|
|
|
|
|
|
public function getinfo()
|