User.php 13 KB

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