User.php 14 KB

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