User.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. namespace app\agent\controller;
  3. use app\common\model\ComjobsCate;
  4. use app\common\model\RensheCode;
  5. use app\common\model\UserTags;
  6. use app\common\model\UserWill;
  7. use think\facade\Session;
  8. use app\agent\BaseController;
  9. use app\common\model\User as UserModel;
  10. use app\common\model\UserAuths as UserAuthsModel;
  11. use app\common\model\UserFollow as UserFollowModel;
  12. use app\common\model\UserGroups as UserGroupsModel;
  13. use app\common\model\Broker as BrokerModel;
  14. use app\common\validate\User as UserValidate;
  15. use think\exception\ValidateException;
  16. use PHPExcel_IOFactory;
  17. use PHPExcel;
  18. class User extends BaseController
  19. {
  20. // 用户跟进记录
  21. public function follow()
  22. {
  23. $userid = input('userid/d');
  24. $user = UserModel::findOrEmpty($userid);
  25. $followlist = UserFollowModel::where('userid', $userid)->order('id', 'desc')->limit(100)->select();
  26. return view('user/follow', [
  27. 'user' => $user,
  28. 'followlist' => $followlist,
  29. ]);
  30. }
  31. public function editFollow()
  32. {
  33. $userid = input('userid/d', 0);
  34. $user = UserModel::findOrEmpty($userid);
  35. if ($user->isEmpty()) {
  36. exit(json_encode([
  37. 'code' => 1,
  38. 'msg' => "用户信息不存在。",
  39. ]));
  40. }
  41. $agent = $this->access_agent;
  42. $broker = BrokerModel::where('agentid', '=', $agent['id'])->findOrEmpty($user->brokerid);
  43. if ($broker->isEmpty()) {
  44. exit(json_encode([
  45. 'code' => 1,
  46. 'msg' => "你无权限上报该用户跟进记录。",
  47. ]));
  48. }
  49. UserFollowModel::create([
  50. 'userid' => $userid,
  51. 'ftype' => input('ftype/s', ""),
  52. 'remark' => input('remark/s', ""),
  53. 'createtime' => time(),
  54. ]);
  55. $followstatus = input('followstatus/d', 1);
  56. $user->save([
  57. 'followstatus' => $followstatus,
  58. ]);
  59. exit(json_encode([
  60. 'code' => 0,
  61. ]));
  62. }
  63. // 用户授权
  64. public function authsList()
  65. {
  66. $userid = input('userid/d');
  67. return view('user/authslist', [
  68. 'userid' => $userid,
  69. ]);
  70. }
  71. public function listAuths()
  72. {
  73. $userid = input('userid/d');
  74. $list = UserAuthsModel::where('userid', $userid)->order('id', 'asc')->append(['identitytype_text'])->select();
  75. $count = UserAuthsModel::where('userid', $userid)->count();
  76. if ($count == 0) {
  77. exit(json_encode([
  78. 'code' => 1,
  79. 'msg' => "未查询到数据",
  80. ]));
  81. }
  82. exit(json_encode([
  83. 'code' => 0,
  84. 'msg' => "",
  85. 'count' => $count,
  86. 'data' => $list,
  87. ]));
  88. }
  89. public function delAuths()
  90. {
  91. $id = input('id/d');
  92. $auths = UserAuthsModel::find($id);
  93. if ($auths->identitytype == 'mobile') {
  94. exit(json_encode([
  95. 'code' => 1,
  96. 'msg' => "手机号授权方式不允许删除",
  97. ]));
  98. }
  99. $result = $auths->delete();
  100. if ($result) {
  101. exit(json_encode([
  102. 'code' => 0,
  103. ]));
  104. }
  105. exit(json_encode([
  106. 'code' => 1,
  107. 'msg' => "删除失败,请稍后重试",
  108. ]));
  109. }
  110. // 用户
  111. public function userList()
  112. {
  113. $agentid = $this->access_agent['id'];
  114. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  115. $brokerlist = BrokerModel::where('agentid', '=', $agentid)->order(['id' => 'desc'])->select();
  116. return view('user/userlist', [
  117. 'groupslist' => $groupslist,
  118. 'brokerlist' => $brokerlist,
  119. ]);
  120. }
  121. public function userForm()
  122. {
  123. $agentid = $this->access_agent['id'];
  124. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  125. $id = input('id/d', 0);
  126. $user = UserModel::whereIn('brokerid', $brokeridarr)->where('brokerid', '<>', 0)->findOrEmpty($id);
  127. $agent = $this->access_agent;
  128. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  129. $brokerlist = BrokerModel::where('agentid', '=', $agentid)->order(['id' => 'desc'])->select();
  130. $willlist = UserWill::select();
  131. $usertags = UserTags::select();
  132. $emptimelist = RensheCode::getList('emp_time');
  133. $communitylist = RensheCode::getList('community')->toArray();
  134. array_push($communitylist, ['code' => 0, 'id' => 0, 'name' => "不限"]);
  135. $comlist = ComjobsCate::select();
  136. return view('user/userform', [
  137. 'brokerlist' => $brokerlist,
  138. 'groupslist' => $groupslist,
  139. 'agent' => $agent,
  140. 'user' => $user,
  141. 'willlist' => $willlist,
  142. 'usertags' => $usertags,
  143. 'emptimelist' => $emptimelist,
  144. 'communitylist' => $communitylist,
  145. 'comlist' => $comlist,
  146. ]);
  147. }
  148. public function fieldUser()
  149. {
  150. $agentid = $this->access_agent['id'];
  151. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  152. $id = input('id/d', 0);
  153. $user = UserModel::whereIn('brokerid', $brokeridarr)->where('brokerid', '<>', 0)->findOrEmpty($id);
  154. if ($user->isEmpty()) {
  155. exit(json_encode([
  156. 'code' => 1,
  157. 'msg' => "信息不存在",
  158. ]));
  159. } else {
  160. $user->save([
  161. input('field/s') => input('value/s'),
  162. ]);
  163. }
  164. exit(json_encode([
  165. 'code' => 0,
  166. ]));
  167. }
  168. public function listUser()
  169. {
  170. $agentid = $this->access_agent['id'];
  171. $limit = input('limit', 20);
  172. $page = input('page', 1);
  173. $map = [];
  174. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  175. if (!empty($brokeridarr)) {
  176. $map[] = ['brokerid', 'in', $brokeridarr];
  177. } else {
  178. $map[] = ['brokerid', '=', -1];
  179. }
  180. $keywords = input('keywords/s');
  181. if (!empty($keywords)) {
  182. $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
  183. }
  184. $groupsid = input('groupsid/d');
  185. if (!empty($groupsid)) {
  186. $map[] = ['groupsid', '=', $groupsid];
  187. }
  188. $brokerid = input('brokerid/d');
  189. if (!empty($brokerid)) {
  190. $map[] = ['brokerid', '=', $brokerid];
  191. }
  192. $status = input('status/d');
  193. if (!empty($status)) {
  194. $map[] = ['status', '=', $status];
  195. }
  196. $authstatus = input('authstatus/d');
  197. if (!empty($authstatus)) {
  198. $map[] = ['authstatus', '=', $authstatus];
  199. }
  200. $followstatus = input('followstatus/d');
  201. if (!empty($followstatus)) {
  202. $map[] = ['followstatus', '=', $followstatus];
  203. }
  204. $list = UserModel::with(['userGroups', 'broker'])->where($map)->order('id', 'desc')->limit($limit)->page($page)->append(['status_text', 'isvip_text', 'authstatus_text', 'followstatus_text'])->select();
  205. $count = UserModel::where($map)->count();
  206. if ($count == 0) {
  207. exit(json_encode([
  208. 'code' => 1,
  209. 'msg' => "未查询到数据",
  210. ]));
  211. }
  212. exit(json_encode([
  213. 'code' => 0,
  214. 'msg' => "",
  215. 'count' => $count,
  216. 'data' => $list,
  217. ]));
  218. }
  219. public function exportUser()
  220. {
  221. $agentid = $this->access_agent['id'];
  222. $map = [];
  223. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  224. $map[] = ['brokerid', 'in', $brokeridarr];
  225. $map[] = ['brokerid', '<>', 0];
  226. $keywords = input('keywords/s');
  227. if (!empty($keywords)) {
  228. $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
  229. }
  230. $groupsid = input('groupsid/d');
  231. if (!empty($groupsid)) {
  232. $map[] = ['groupsid', '=', $groupsid];
  233. }
  234. $brokerid = input('brokerid/d');
  235. if (!empty($brokerid)) {
  236. $map[] = ['brokerid', '=', $brokerid];
  237. }
  238. $status = input('status/d');
  239. if (!empty($status)) {
  240. $map[] = ['status', '=', $status];
  241. }
  242. $authstatus = input('authstatus/d');
  243. if (!empty($authstatus)) {
  244. $map[] = ['authstatus', '=', $authstatus];
  245. }
  246. $followstatus = input('followstatus/d');
  247. if (!empty($followstatus)) {
  248. $map[] = ['followstatus', '=', $followstatus];
  249. }
  250. $xlsData = UserModel::with(['userGroups', 'broker'])->where($map)->order('id', 'desc')->append(['status_text', 'isvip_text', 'authstatus_text', 'followstatus_text'])->select()->toArray();
  251. $xlsCell = [
  252. ['id', '表ID'],
  253. ['nickname', '昵称'],
  254. ['realname', '姓名'],
  255. ['mobile', '手机号'],
  256. ['status_text', '状态'],
  257. ['isvip_text', '是否VIP'],
  258. ['authstatus_text', '是否实名认证'],
  259. ['idcard', '身份证号'],
  260. ['gender', '性别', [1 => '男', 2 => '女']],
  261. ['birthday', '出生日期'],
  262. ['address', '现居住地'],
  263. ['education', '学历'],
  264. ['bankcard.openbank', '开户行'],
  265. ['bankcard.account', '账户名'],
  266. ['bankcard.number', '账户号'],
  267. ['followstatus_text', '跟进状态'],
  268. ['userGroups.title', '用户组'],
  269. ['broker.title', '经纪人'],
  270. ['createtime', '注册时间'],
  271. ];
  272. export_excel("系统用户", $xlsCell, $xlsData);
  273. }
  274. public function editUser()
  275. {
  276. $id = input('id/d');
  277. $mobile = input('mobile/s');
  278. $vdata = [
  279. 'id' => $id,
  280. 'mobile' => $mobile,
  281. ];
  282. try {
  283. validate(UserValidate::class)->check($vdata);
  284. } catch (ValidateException $e) {
  285. exit(json_encode([
  286. 'code' => 1,
  287. 'msg' => $e->getError(),
  288. ]));
  289. }
  290. $data = [
  291. 'groupsid' => input('groupsid/d', 0),
  292. 'brokerid' => input('brokerid/d', 0),
  293. 'nickname' => input('nickname/s', ""),
  294. 'avatar' => input('avatar/s', ""),
  295. 'realname' => input('realname/s', ""),
  296. 'mobile' => $mobile,
  297. 'status' => input('status/d', 1),
  298. 'isvip' => input('isvip/d', 1),
  299. 'authstatus' => input('authstatus/d', 1),
  300. 'authremark' => input('authremark/s', ""),
  301. 'idcardzpic' => input('idcardzpic/s', ""),
  302. 'idcardfpic' => input('idcardfpic/s', ""),
  303. 'idcard' => input('idcard/s', ""),
  304. 'gender' => input('gender/d', 1),
  305. 'birthday' => input('birthday/s', ""),
  306. 'address' => input('address/s', ""),
  307. 'education' => input('education/s', ""),
  308. 'jobintention' => input('jobintention/s', ""),
  309. 'workexperience' => input('workexperience/s', ""),
  310. 'eduexperience' => input('eduexperience/s', ""),
  311. 'followstatus' => input('followstatus/d', 1),
  312. 'bankcard' => input('bankcard/a', []),
  313. ];
  314. $password = input('password/s');
  315. if (empty($id)) {
  316. $data['integral'] = 0;
  317. $data['inttotal'] = 0;
  318. $data['createtime'] = time();
  319. $user = UserModel::create($data);
  320. $auths = UserAuthsModel::create([
  321. 'userid' => $user->id,
  322. 'identitytype' => "mobile",
  323. 'identifier' => $mobile,
  324. 'password' => empty($password) ? md5("123456789") : md5($password),
  325. 'logintime' => time(),
  326. 'loginip' => $_SERVER['SERVER_ADDR'],
  327. 'wxampcode' => "",
  328. ]);
  329. } else {
  330. $data['id'] = $id;
  331. $user = UserModel::update($data);
  332. $adata = ['identifier' => $mobile];
  333. if (!empty($password)) {
  334. $adata['password'] = md5($password);
  335. }
  336. UserAuthsModel::update($adata, ['userid' => $id, 'identitytype' => 'mobile']);
  337. }
  338. exit(json_encode([
  339. 'code' => 0,
  340. ]));
  341. }
  342. }