| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 | 
							- <?php
 
- namespace app\agent\controller;
 
- use app\common\model\ComjobsCate;
 
- use app\common\model\RensheCode;
 
- use app\common\model\UserTags;
 
- use app\common\model\UserWill;
 
- use think\facade\Session;
 
- use app\agent\BaseController;
 
- use app\common\model\User as UserModel;
 
- use app\common\model\UserAuths as UserAuthsModel;
 
- use app\common\model\UserFollow as UserFollowModel;
 
- use app\common\model\UserGroups as UserGroupsModel;
 
- use app\common\model\Broker as BrokerModel;
 
- use app\common\validate\User as UserValidate;
 
- use think\exception\ValidateException;
 
- use PHPExcel_IOFactory;
 
- use PHPExcel;
 
- class User extends BaseController
 
- {
 
-     // 用户跟进记录
 
-     public function follow()
 
-     {
 
-         $userid     = input('userid/d');
 
-         $user       = UserModel::findOrEmpty($userid);
 
-         $followlist = UserFollowModel::where('userid', $userid)->order('id', 'desc')->limit(100)->select();
 
-         return view('user/follow', [
 
-             'user'       => $user,
 
-             'followlist' => $followlist,
 
-         ]);
 
-     }
 
-     public function editFollow()
 
-     {
 
-         $userid = input('userid/d', 0);
 
-         $user   = UserModel::findOrEmpty($userid);
 
-         if ($user->isEmpty()) {
 
-             exit(json_encode([
 
-                 'code' => 1,
 
-                 'msg'  => "用户信息不存在。",
 
-             ]));
 
-         }
 
-         $agent  = $this->access_agent;
 
-         $broker = BrokerModel::where('agentid', '=', $agent['id'])->findOrEmpty($user->brokerid);
 
-         if ($broker->isEmpty()) {
 
-             exit(json_encode([
 
-                 'code' => 1,
 
-                 'msg'  => "你无权限上报该用户跟进记录。",
 
-             ]));
 
-         }
 
-         UserFollowModel::create([
 
-             'userid'     => $userid,
 
-             'ftype'      => input('ftype/s', ""),
 
-             'remark'     => input('remark/s', ""),
 
-             'createtime' => time(),
 
-         ]);
 
-         $followstatus = input('followstatus/d', 1);
 
-         $user->save([
 
-             'followstatus' => $followstatus,
 
-         ]);
 
-         exit(json_encode([
 
-             'code' => 0,
 
-         ]));
 
-     }
 
-     // 用户授权
 
-     public function authsList()
 
-     {
 
-         $userid = input('userid/d');
 
-         return view('user/authslist', [
 
-             'userid' => $userid,
 
-         ]);
 
-     }
 
-     public function listAuths()
 
-     {
 
-         $userid = input('userid/d');
 
-         $list   = UserAuthsModel::where('userid', $userid)->order('id', 'asc')->append(['identitytype_text'])->select();
 
-         $count  = UserAuthsModel::where('userid', $userid)->count();
 
-         if ($count == 0) {
 
-             exit(json_encode([
 
-                 'code' => 1,
 
-                 'msg'  => "未查询到数据",
 
-             ]));
 
-         }
 
-         exit(json_encode([
 
-             'code'  => 0,
 
-             'msg'   => "",
 
-             'count' => $count,
 
-             'data'  => $list,
 
-         ]));
 
-     }
 
-     public function delAuths()
 
-     {
 
-         $id    = input('id/d');
 
-         $auths = UserAuthsModel::find($id);
 
-         if ($auths->identitytype == 'mobile') {
 
-             exit(json_encode([
 
-                 'code' => 1,
 
-                 'msg'  => "手机号授权方式不允许删除",
 
-             ]));
 
-         }
 
-         $result = $auths->delete();
 
-         if ($result) {
 
-             exit(json_encode([
 
-                 'code' => 0,
 
-             ]));
 
-         }
 
-         exit(json_encode([
 
-             'code' => 1,
 
-             'msg'  => "删除失败,请稍后重试",
 
-         ]));
 
-     }
 
-     // 用户
 
-     public function userList()
 
-     {
 
-         $agentid    = $this->access_agent['id'];
 
-         $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
 
-         $brokerlist = BrokerModel::where('agentid', '=', $agentid)->order(['id' => 'desc'])->select();
 
-         return view('user/userlist', [
 
-             'groupslist' => $groupslist,
 
-             'brokerlist' => $brokerlist,
 
-         ]);
 
-     }
 
-     public function userForm()
 
-     {
 
-         $agentid       = $this->access_agent['id'];
 
-         $brokeridarr   = BrokerModel::where('agentid', '=', $agentid)->column('id');
 
-         $id            = input('id/d', 0);
 
-         $user          = UserModel::whereIn('brokerid', $brokeridarr)->where('brokerid', '<>', 0)->findOrEmpty($id);
 
-         $agent         = $this->access_agent;
 
-         $groupslist    = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
 
-         $brokerlist    = BrokerModel::where('agentid', '=', $agentid)->order(['id' => 'desc'])->select();
 
-         $willlist      = UserWill::select();
 
-         $usertags      = UserTags::select();
 
-         $emptimelist   = RensheCode::getList('emp_time');
 
-         $communitylist = RensheCode::getList('community')->toArray();
 
-         array_push($communitylist, ['code' => 0, 'id' => 0, 'name' => "不限"]);
 
-         $comlist = ComjobsCate::select();
 
-         return view('user/userform', [
 
-             'brokerlist'    => $brokerlist,
 
-             'groupslist'    => $groupslist,
 
-             'agent'         => $agent,
 
-             'user'          => $user,
 
-             'willlist'      => $willlist,
 
-             'usertags'      => $usertags,
 
-             'emptimelist'   => $emptimelist,
 
-             'communitylist' => $communitylist,
 
-             'comlist'       => $comlist,
 
-         ]);
 
-     }
 
-     public function fieldUser()
 
-     {
 
-         $agentid     = $this->access_agent['id'];
 
-         $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
 
-         $id          = input('id/d', 0);
 
-         $user        = UserModel::whereIn('brokerid', $brokeridarr)->where('brokerid', '<>', 0)->findOrEmpty($id);
 
-         if ($user->isEmpty()) {
 
-             exit(json_encode([
 
-                 'code' => 1,
 
-                 'msg'  => "信息不存在",
 
-             ]));
 
-         } else {
 
-             $user->save([
 
-                 input('field/s') => input('value/s'),
 
-             ]);
 
-         }
 
-         exit(json_encode([
 
-             'code' => 0,
 
-         ]));
 
-     }
 
-     public function listUser()
 
-     {
 
-         $agentid     = $this->access_agent['id'];
 
-         $limit       = input('limit', 20);
 
-         $page        = input('page', 1);
 
-         $map         = [];
 
-         $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
 
-         if (!empty($brokeridarr)) {
 
-             $map[] = ['brokerid', 'in', $brokeridarr];
 
-         } else {
 
-             $map[] = ['brokerid', '=', -1];
 
-         }
 
-         $keywords = input('keywords/s');
 
-         if (!empty($keywords)) {
 
-             $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
 
-         }
 
-         $groupsid = input('groupsid/d');
 
-         if (!empty($groupsid)) {
 
-             $map[] = ['groupsid', '=', $groupsid];
 
-         }
 
-         $brokerid = input('brokerid/d');
 
-         if (!empty($brokerid)) {
 
-             $map[] = ['brokerid', '=', $brokerid];
 
-         }
 
-         $status = input('status/d');
 
-         if (!empty($status)) {
 
-             $map[] = ['status', '=', $status];
 
-         }
 
-         $authstatus = input('authstatus/d');
 
-         if (!empty($authstatus)) {
 
-             $map[] = ['authstatus', '=', $authstatus];
 
-         }
 
-         $followstatus = input('followstatus/d');
 
-         if (!empty($followstatus)) {
 
-             $map[] = ['followstatus', '=', $followstatus];
 
-         }
 
-         $list  = UserModel::with(['userGroups', 'broker'])->where($map)->order('id', 'desc')->limit($limit)->page($page)->append(['status_text', 'isvip_text', 'authstatus_text', 'followstatus_text'])->select();
 
-         $count = UserModel::where($map)->count();
 
-         if ($count == 0) {
 
-             exit(json_encode([
 
-                 'code' => 1,
 
-                 'msg'  => "未查询到数据",
 
-             ]));
 
-         }
 
-         exit(json_encode([
 
-             'code'  => 0,
 
-             'msg'   => "",
 
-             'count' => $count,
 
-             'data'  => $list,
 
-         ]));
 
-     }
 
-     public function exportUser()
 
-     {
 
-         $agentid     = $this->access_agent['id'];
 
-         $map         = [];
 
-         $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
 
-         $map[]       = ['brokerid', 'in', $brokeridarr];
 
-         $map[]       = ['brokerid', '<>', 0];
 
-         $keywords    = input('keywords/s');
 
-         if (!empty($keywords)) {
 
-             $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
 
-         }
 
-         $groupsid = input('groupsid/d');
 
-         if (!empty($groupsid)) {
 
-             $map[] = ['groupsid', '=', $groupsid];
 
-         }
 
-         $brokerid = input('brokerid/d');
 
-         if (!empty($brokerid)) {
 
-             $map[] = ['brokerid', '=', $brokerid];
 
-         }
 
-         $status = input('status/d');
 
-         if (!empty($status)) {
 
-             $map[] = ['status', '=', $status];
 
-         }
 
-         $authstatus = input('authstatus/d');
 
-         if (!empty($authstatus)) {
 
-             $map[] = ['authstatus', '=', $authstatus];
 
-         }
 
-         $followstatus = input('followstatus/d');
 
-         if (!empty($followstatus)) {
 
-             $map[] = ['followstatus', '=', $followstatus];
 
-         }
 
-         $xlsData = UserModel::with(['userGroups', 'broker'])->where($map)->order('id', 'desc')->append(['status_text', 'isvip_text', 'authstatus_text', 'followstatus_text'])->select()->toArray();
 
-         $xlsCell = [
 
-             ['id', '表ID'],
 
-             ['nickname', '昵称'],
 
-             ['realname', '姓名'],
 
-             ['mobile', '手机号'],
 
-             ['status_text', '状态'],
 
-             ['isvip_text', '是否VIP'],
 
-             ['authstatus_text', '是否实名认证'],
 
-             ['idcard', '身份证号'],
 
-             ['gender', '性别', [1 => '男', 2 => '女']],
 
-             ['birthday', '出生日期'],
 
-             ['address', '现居住地'],
 
-             ['education', '学历'],
 
-             ['bankcard.openbank', '开户行'],
 
-             ['bankcard.account', '账户名'],
 
-             ['bankcard.number', '账户号'],
 
-             ['followstatus_text', '跟进状态'],
 
-             ['userGroups.title', '用户组'],
 
-             ['broker.title', '经纪人'],
 
-             ['createtime', '注册时间'],
 
-         ];
 
-         export_excel("系统用户", $xlsCell, $xlsData);
 
-     }
 
-     public function editUser()
 
-     {
 
-         $id     = input('id/d');
 
-         $mobile = input('mobile/s');
 
-         $vdata  = [
 
-             'id'     => $id,
 
-             'mobile' => $mobile,
 
-         ];
 
-         try {
 
-             validate(UserValidate::class)->check($vdata);
 
-         } catch (ValidateException $e) {
 
-             exit(json_encode([
 
-                 'code' => 1,
 
-                 'msg'  => $e->getError(),
 
-             ]));
 
-         }
 
-         $data     = [
 
-             'groupsid'       => input('groupsid/d', 0),
 
-             'brokerid'       => input('brokerid/d', 0),
 
-             'nickname'       => input('nickname/s', ""),
 
-             'avatar'         => input('avatar/s', ""),
 
-             'realname'       => input('realname/s', ""),
 
-             'mobile'         => $mobile,
 
-             'status'         => input('status/d', 1),
 
-             'isvip'          => input('isvip/d', 1),
 
-             'authstatus'     => input('authstatus/d', 1),
 
-             'authremark'     => input('authremark/s', ""),
 
-             'idcardzpic'     => input('idcardzpic/s', ""),
 
-             'idcardfpic'     => input('idcardfpic/s', ""),
 
-             'idcard'         => input('idcard/s', ""),
 
-             'gender'         => input('gender/d', 1),
 
-             'birthday'       => input('birthday/s', ""),
 
-             'address'        => input('address/s', ""),
 
-             'education'      => input('education/s', ""),
 
-             'jobintention'   => input('jobintention/s', ""),
 
-             'workexperience' => input('workexperience/s', ""),
 
-             'eduexperience'  => input('eduexperience/s', ""),
 
-             'followstatus'   => input('followstatus/d', 1),
 
-             'bankcard'       => input('bankcard/a', []),
 
-         ];
 
-         $password = input('password/s');
 
-         if (empty($id)) {
 
-             $data['integral']   = 0;
 
-             $data['inttotal']   = 0;
 
-             $data['createtime'] = time();
 
-             $user               = UserModel::create($data);
 
-             $auths              = UserAuthsModel::create([
 
-                 'userid'       => $user->id,
 
-                 'identitytype' => "mobile",
 
-                 'identifier'   => $mobile,
 
-                 'password'     => empty($password) ? md5("123456789") : md5($password),
 
-                 'logintime'    => time(),
 
-                 'loginip'      => $_SERVER['SERVER_ADDR'],
 
-                 'wxampcode'    => "",
 
-             ]);
 
-         } else {
 
-             $data['id'] = $id;
 
-             $user       = UserModel::update($data);
 
-             $adata      = ['identifier' => $mobile];
 
-             if (!empty($password)) {
 
-                 $adata['password'] = md5($password);
 
-             }
 
-             UserAuthsModel::update($adata, ['userid' => $id, 'identitytype' => 'mobile']);
 
-         }
 
-         exit(json_encode([
 
-             'code' => 0,
 
-         ]));
 
-     }
 
- }
 
 
  |