User.php 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\RensheCode;
  4. use app\common\model\UserWill;
  5. use app\admin\BaseController;
  6. use app\common\model\User as UserModel;
  7. use app\common\model\UserAuths as UserAuthsModel;
  8. use app\common\model\UserFollow as UserFollowModel;
  9. use app\common\model\UserGroups as UserGroupsModel;
  10. use app\common\model\UserPart as UserPartModel;
  11. use app\common\model\UserIntegral as UserIntegralModel;
  12. use app\common\model\UserRank as UserRankModel;
  13. use app\common\model\UserParam as UserParamModel;
  14. use app\common\model\ComjobsCate as ComjobsCateModel;
  15. use app\common\model\Agent as AgentModel;
  16. use app\common\model\Broker as BrokerModel;
  17. use app\common\validate\User as UserValidate;
  18. use think\exception\ValidateException;
  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. UserFollowModel::create([
  43. 'userid' => $userid,
  44. 'ftype' => input('ftype/s', ""),
  45. 'remark' => input('remark/s', ""),
  46. 'createtime' => time(),
  47. ]);
  48. $followstatus = input('followstatus/d', 1);
  49. $user->save([
  50. 'followstatus' => $followstatus,
  51. ]);
  52. exit(json_encode([
  53. 'code' => 0,
  54. ]));
  55. }
  56. // 邀请排行榜
  57. public function rankList()
  58. {
  59. return view('user/ranklist');
  60. }
  61. public function rankForm()
  62. {
  63. $id = input('id/d');
  64. $rank = UserRankModel::findOrEmpty($id);
  65. return view('user/rankform', [
  66. 'rank' => $rank,
  67. ]);
  68. }
  69. public function editRank()
  70. {
  71. $id = input('id/d');
  72. $rank = UserRankModel::findOrEmpty($id);
  73. $rank->save([
  74. 'realname' => input('realname/s'),
  75. 'mobile' => input('mobile/s'),
  76. 'partnumber' => input('partnumber/d', 0),
  77. ]);
  78. exit(json_encode([
  79. 'code' => 0,
  80. ]));
  81. }
  82. public function fieldRank()
  83. {
  84. $id = input('id/d', 0);
  85. $rank = UserRankModel::findOrEmpty($id);
  86. if ($rank->isEmpty()) {
  87. exit(json_encode([
  88. 'code' => 1,
  89. 'msg' => "信息不存在",
  90. ]));
  91. } else {
  92. $rank->save([
  93. input('field/s') => input('value'),
  94. ]);
  95. }
  96. exit(json_encode([
  97. 'code' => 0,
  98. ]));
  99. }
  100. public function listRank()
  101. {
  102. $limit = input('limit');
  103. $page = input('page');
  104. $map = [];
  105. $list = UserRankModel::where($map)->order('partnumber', 'desc')->limit($limit)->page($page)->select();
  106. $count = UserRankModel::where($map)->count();
  107. if ($count == 0) {
  108. exit(json_encode([
  109. 'code' => 1,
  110. 'msg' => "未查询到数据",
  111. ]));
  112. }
  113. exit(json_encode([
  114. 'code' => 0,
  115. 'msg' => "",
  116. 'count' => $count,
  117. 'data' => $list,
  118. ]));
  119. }
  120. public function delRank()
  121. {
  122. $idarr = input('idarr/a');
  123. UserRankModel::whereIn('id', $idarr)->delete();
  124. exit(json_encode([
  125. 'code' => 0,
  126. 'msg' => "",
  127. ]));
  128. }
  129. // 邀请记录
  130. public function partList()
  131. {
  132. return view('user/partlist');
  133. }
  134. public function listPart()
  135. {
  136. $limit = input('limit');
  137. $page = input('page');
  138. $map = [];
  139. $keywords = input('keywords/s', "");
  140. $status = input('status/d', 0);
  141. if (!empty($status)) {
  142. $map[] = ['UserPart.status', '=', $status];
  143. }
  144. $list = UserPartModel::hasWhere('puser', [['realname|mobile', 'like', '%' . $keywords . '%', 'or']])->with(['puser', 'user'])->where($map)->order('id', 'desc')->limit($limit)->page($page)->append(['status_text'])->select();
  145. $count = UserPartModel::hasWhere('puser', [['realname|mobile', 'like', '%' . $keywords . '%', 'or']])->where($map)->count();
  146. if ($count == 0) {
  147. exit(json_encode([
  148. 'code' => 1,
  149. 'msg' => "未查询到数据",
  150. ]));
  151. }
  152. exit(json_encode([
  153. 'code' => 0,
  154. 'msg' => "",
  155. 'count' => $count,
  156. 'data' => $list,
  157. ]));
  158. }
  159. public function exportPart()
  160. {
  161. $map = [];
  162. $keywords = input('keywords/s', "");
  163. $status = input('status/d', 0);
  164. if (!empty($status)) {
  165. $map[] = ['UserPart.status', '=', $status];
  166. }
  167. $xlsData = UserPartModel::hasWhere('puser', [['realname|mobile', 'like', '%' . $keywords . '%', 'or']])->with(['puser', 'user'])->where($map)->order('id', 'desc')->select()->toArray();
  168. $xlsCell = [
  169. ['id', '表ID'],
  170. ['puser.nickname', '邀请人昵称'],
  171. ['puser.realname', '邀请人姓名'],
  172. ['puser.mobile', '邀请人手机号'],
  173. ['puser.bankcard.openbank', '邀请人开户行'],
  174. ['puser.bankcard.account', '邀请人帐户名'],
  175. ['puser.bankcard.number', '邀请人账户号'],
  176. ['user.nickname', '被邀请人昵称'],
  177. ['user.realname', '被邀请人姓名'],
  178. ['user.mobile', '被邀请人手机号'],
  179. ['status', '状态', [1 => '未入职', 2 => '已入职', 3 => '已发放']],
  180. ['redmoney', '奖金金额'],
  181. ['createtime', '推荐时间'],
  182. ];
  183. export_excel("系统用户", $xlsCell, $xlsData);
  184. }
  185. public function fieldPart()
  186. {
  187. $id = input('id/d', 0);
  188. $part = UserPartModel::findOrEmpty($id);
  189. if ($part->isEmpty()) {
  190. exit(json_encode([
  191. 'code' => 1,
  192. 'msg' => "信息不存在",
  193. ]));
  194. } else {
  195. $part->save([
  196. input('field/s') => input('value'),
  197. ]);
  198. }
  199. exit(json_encode([
  200. 'code' => 0,
  201. ]));
  202. }
  203. public function partForm()
  204. {
  205. $id = input('id/d');
  206. $part = UserPartModel::with(['puser', 'user'])->findOrEmpty($id);
  207. return view('user/partform', [
  208. 'part' => $part,
  209. ]);
  210. }
  211. public function editPart()
  212. {
  213. $id = input('id/d');
  214. $part = UserPartModel::findOrEmpty($id);
  215. $part->save([
  216. 'status' => input('status/d', 1),
  217. 'redmoney' => input('redmoney/d', 0),
  218. ]);
  219. exit(json_encode([
  220. 'code' => 0,
  221. ]));
  222. }
  223. public function delPart()
  224. {
  225. $idarr = input('idarr/a');
  226. UserPartModel::whereIn('id', $idarr)->delete();
  227. exit(json_encode([
  228. 'code' => 0,
  229. 'msg' => "",
  230. ]));
  231. }
  232. // 用户积分
  233. public function integralList()
  234. {
  235. return view('user/integrallist');
  236. }
  237. public function listIntegral()
  238. {
  239. $limit = input('limit');
  240. $page = input('page');
  241. $map = [];
  242. $keywords = input('keywords/s', "");
  243. $itype = input('itype/d', 0);
  244. if (!empty($itype)) {
  245. $map[] = ['itype', '=', $itype];
  246. }
  247. $status = input('status/d', 0);
  248. if (!empty($status)) {
  249. $map[] = ['status', '=', $status];
  250. }
  251. $list = UserIntegralModel::hasWhere('user', [['realname|mobile', 'like', '%' . $keywords . '%', 'or']])->with(['user'])->where($map)->order('id', 'desc')->limit($limit)->page($page)->select()->append(['itype_text', 'status_text']);
  252. $count = UserIntegralModel::hasWhere('user', [['realname|mobile', 'like', '%' . $keywords . '%', 'or']])->where($map)->count();
  253. if ($count == 0) {
  254. exit(json_encode([
  255. 'code' => 1,
  256. 'msg' => "未查询到数据",
  257. ]));
  258. }
  259. exit(json_encode([
  260. 'code' => 0,
  261. 'msg' => "",
  262. 'count' => $count,
  263. 'data' => $list,
  264. ]));
  265. }
  266. public function exportIntegral()
  267. {
  268. $map = [];
  269. $keywords = input('keywords/s', "");
  270. $itype = input('itype/d', 0);
  271. if (!empty($itype)) {
  272. $map[] = ['itype', '=', $itype];
  273. }
  274. $xlsData = UserIntegralModel::hasWhere('user', [['realname|mobile', 'like', '%' . $keywords . '%', 'or']])->with(['user'])->where($map)->order('id', 'desc')->select()->append(['itype_text', 'status_text'])->toArray();
  275. $xlsCell = [
  276. ['id', '表ID'],
  277. ['user.nickname', '昵称'],
  278. ['user.realname', '姓名'],
  279. ['user.mobile', '手机号'],
  280. ['user.bankcard.openbank', '开户行'],
  281. ['user.bankcard.account', '帐户名'],
  282. ['user.bankcard.number', '账户号'],
  283. ['title', '积分标题'],
  284. ['itype_text', '类型'],
  285. ['status_text', '状态'],
  286. ['intvalue', '积分变更值'],
  287. ['intmoney', '积分金额'],
  288. ['remark', '备注'],
  289. ['createtime', '注册时间'],
  290. ];
  291. export_excel("用户积分", $xlsCell, $xlsData);
  292. }
  293. public function fieldIntegral()
  294. {
  295. $id = input('id/d', 0);
  296. $integral = UserIntegralModel::findOrEmpty($id);
  297. if ($integral->isEmpty()) {
  298. exit(json_encode([
  299. 'code' => 1,
  300. 'msg' => "信息不存在",
  301. ]));
  302. } else {
  303. $integral->save([
  304. input('field/s') => input('value'),
  305. ]);
  306. }
  307. exit(json_encode([
  308. 'code' => 0,
  309. ]));
  310. }
  311. public function integralUpdate()
  312. {
  313. $id = input('id/d', 0);
  314. $integral = UserIntegralModel::with('user')->findOrEmpty($id);
  315. return view('user/integralupdate', [
  316. 'integral' => $integral,
  317. ]);
  318. }
  319. public function updateIntegral()
  320. {
  321. $id = input('id/d', 0);
  322. $integral = UserIntegralModel::findOrEmpty($id);
  323. if ($integral->isEmpty()) {
  324. exit(json_encode([
  325. 'code' => 1,
  326. 'msg' => "用户积分记录不存在",
  327. ]));
  328. }
  329. $createtime = input('createtime/s', date("Y-m-d H:i:s"));
  330. $integral->save([
  331. 'title' => input('title/s', ""),
  332. 'intvalue' => input('intvalue/d', 0),
  333. 'intmoney' => input('intmoney/f', 0.00),
  334. 'remark' => input('remark/s', ""),
  335. 'itype' => input('itype/d', 1),
  336. 'status' => input('status/d', 1),
  337. 'createtime' => $createtime,
  338. 'yeartime' => date("Y", strtotime($createtime)),
  339. 'monthtime' => date("Ym", strtotime($createtime)),
  340. ]);
  341. exit(json_encode([
  342. 'code' => 0,
  343. ]));
  344. }
  345. public function statusIntegral()
  346. {
  347. $id = input('id/d');
  348. $integral = UserIntegralModel::where(['itype' => 3])->find($id);
  349. if ($integral == null) {
  350. exit(json_encode([
  351. 'code' => 1,
  352. 'msg' => "该记录非兑现类型",
  353. ]));
  354. } elseif ($integral->status == 1) {
  355. $integral->save([
  356. 'status' => 2,
  357. ]);
  358. } elseif ($integral->status == 2) {
  359. $integral->save([
  360. 'status' => 1,
  361. ]);
  362. } else {
  363. exit(json_encode([
  364. 'code' => 1,
  365. 'msg' => "该记录非兑现类型。",
  366. ]));
  367. }
  368. exit(json_encode([
  369. 'code' => 0,
  370. ]));
  371. }
  372. public function statusIntegralAll()
  373. {
  374. $idarr = input('idarr/a');
  375. UserIntegralModel::update(['status' => 2], ['status' => 1, 'itype' => 3, 'id' => $idarr]);
  376. exit(json_encode([
  377. 'code' => 0,
  378. 'msg' => "",
  379. ]));
  380. }
  381. public function delIntegral()
  382. {
  383. $idarr = input('idarr/a');
  384. UserIntegralModel::whereIn('id', $idarr)->delete();
  385. exit(json_encode([
  386. 'code' => 0,
  387. 'msg' => "",
  388. ]));
  389. }
  390. public function integralForm()
  391. {
  392. $userid = input('userid/d');
  393. $user = UserModel::findOrEmpty($userid);
  394. return view('user/integralform', [
  395. 'user' => $user,
  396. ]);
  397. }
  398. public function editIntegral()
  399. {
  400. $userid = input('userid/d');
  401. $user = UserModel::findOrEmpty($userid);
  402. $intvalue = input('intvalue/d', 0);
  403. if ($intvalue == 0) {
  404. exit(json_encode([
  405. 'code' => 1,
  406. 'msg' => "积分变更值不能为0",
  407. ]));
  408. }
  409. $data = [
  410. 'userid' => $userid,
  411. 'title' => input('title/s'),
  412. 'intvalue' => $intvalue,
  413. 'intmoney' => input('intmoney/s', 0.00),
  414. 'onlycontent' => "",
  415. 'remark' => input('remark/s'),
  416. 'itype' => input('itype/d'),
  417. 'status' => 2,
  418. 'createtime' => input('createtime/s'),
  419. 'yeartime' => date("Y"),
  420. 'monthtime' => date("Ym"),
  421. ];
  422. UserIntegralModel::create($data);
  423. $udata = [];
  424. $udata['integral'] = intval($user->integral) + $intvalue;
  425. $isinttotal = input('isinttotal/d', 0);
  426. if ($isinttotal == 1) {
  427. $udata['inttotal'] = intval($user->inttotal) + $intvalue;
  428. }
  429. $user->save($udata);
  430. exit(json_encode([
  431. 'code' => 0,
  432. ]));
  433. }
  434. // 用户授权
  435. public function authsList()
  436. {
  437. $userid = input('userid/d');
  438. return view('user/authslist', [
  439. 'userid' => $userid,
  440. ]);
  441. }
  442. public function listAuths()
  443. {
  444. $userid = input('userid/d');
  445. $list = UserAuthsModel::where('userid', $userid)->order('id', 'asc')->append(['identitytype_text'])->select();
  446. $count = UserAuthsModel::where('userid', $userid)->count();
  447. if ($count == 0) {
  448. exit(json_encode([
  449. 'code' => 1,
  450. 'msg' => "未查询到数据",
  451. ]));
  452. }
  453. exit(json_encode([
  454. 'code' => 0,
  455. 'msg' => "",
  456. 'count' => $count,
  457. 'data' => $list,
  458. ]));
  459. }
  460. public function delAuths()
  461. {
  462. $id = input('id/d');
  463. $auths = UserAuthsModel::find($id);
  464. if ($auths->identitytype == 'mobile') {
  465. exit(json_encode([
  466. 'code' => 1,
  467. 'msg' => "手机号授权方式不允许删除",
  468. ]));
  469. }
  470. $result = $auths->delete();
  471. if ($result) {
  472. exit(json_encode([
  473. 'code' => 0,
  474. ]));
  475. }
  476. exit(json_encode([
  477. 'code' => 1,
  478. 'msg' => "删除失败,请稍后重试",
  479. ]));
  480. }
  481. // 用户
  482. public function userPublic()
  483. {
  484. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  485. $agentlist = AgentModel::with('broker')->order(['id' => 'desc'])->select();
  486. return view('user/userpublic', [
  487. 'groupslist' => $groupslist,
  488. 'agentlist' => $agentlist,
  489. ]);
  490. }
  491. public function userList()
  492. {
  493. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  494. $agentlist = AgentModel::with('broker')->order(['id' => 'desc'])->select();
  495. return view('user/userlist', [
  496. 'groupslist' => $groupslist,
  497. 'agentlist' => $agentlist,
  498. ]);
  499. }
  500. public function userForm()
  501. {
  502. $id = input('id/d', 0);
  503. $user = UserModel::with(['broker'])->findOrEmpty($id);
  504. $agentlist = AgentModel::with('broker')->order(['id' => 'asc'])->select();
  505. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  506. $willlist = UserWill::select();
  507. return view('user/userform', [
  508. 'groupslist' => $groupslist,
  509. 'willlist' => $willlist,
  510. 'agentlist' => $agentlist,
  511. 'user' => $user,
  512. ]);
  513. }
  514. public function fieldUser()
  515. {
  516. $id = input('id/d', 0);
  517. $user = UserModel::findOrEmpty($id);
  518. if ($user->isEmpty()) {
  519. exit(json_encode([
  520. 'code' => 1,
  521. 'msg' => "信息不存在",
  522. ]));
  523. } else {
  524. $user->save([
  525. input('field/s') => input('value'),
  526. ]);
  527. }
  528. exit(json_encode([
  529. 'code' => 0,
  530. ]));
  531. }
  532. public function listUser()
  533. {
  534. $limit = input('limit');
  535. $page = input('page');
  536. $map = [];
  537. $keywords = input('keywords/s');
  538. if (!empty($keywords)) {
  539. $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
  540. }
  541. $groupsid = input('groupsid/d');
  542. if (!empty($groupsid)) {
  543. $map[] = ['groupsid', '=', $groupsid];
  544. }
  545. $ispublic = input('ispublic/d', 0);
  546. if ($ispublic == 0) {
  547. $agentbrokerarr = explode(",", input('agentbroker/s'));
  548. $agentid = isset($agentbrokerarr[0]) ? $agentbrokerarr[0] : 0;
  549. if (!empty($agentid)) {
  550. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  551. $map[] = ['brokerid', 'in', $brokeridarr];
  552. $map[] = ['brokerid', '<>', 0];
  553. }
  554. $brokerid = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
  555. if (!empty($brokerid)) {
  556. $map[] = ['brokerid', '=', $brokerid];
  557. }
  558. } else {
  559. $map[] = ['brokerid', '=', 0];
  560. }
  561. $status = input('status/d');
  562. if (!empty($status)) {
  563. $map[] = ['status', '=', $status];
  564. }
  565. $authstatus = input('authstatus/d');
  566. if (!empty($authstatus)) {
  567. $map[] = ['authstatus', '=', $authstatus];
  568. }
  569. $followstatus = input('followstatus/d');
  570. if (!empty($followstatus)) {
  571. $map[] = ['followstatus', '=', $followstatus];
  572. }
  573. $list = UserModel::with(['userGroups', 'broker' => ['agent', 'worker']])->withCount('userPart')->where($map)->order('id', 'desc')->limit($limit)->page($page)->append(['status_text', 'isvip_text', 'authstatus_text', 'followstatus_text', 'education_text', 'worker_text', 'jobintention_text'])->select();
  574. $count = UserModel::where($map)->count();
  575. if ($count == 0) {
  576. exit(json_encode([
  577. 'code' => 1,
  578. 'msg' => "未查询到数据",
  579. ]));
  580. }
  581. exit(json_encode([
  582. 'code' => 0,
  583. 'msg' => "",
  584. 'count' => $count,
  585. 'data' => $list,
  586. ]));
  587. }
  588. public function exportUser()
  589. {
  590. $map = [];
  591. $keywords = input('keywords/s');
  592. if (!empty($keywords)) {
  593. $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
  594. }
  595. $groupsid = input('groupsid/d');
  596. if (!empty($groupsid)) {
  597. $map[] = ['groupsid', '=', $groupsid];
  598. }
  599. $agentbrokerarr = explode(",", input('agentbroker/s'));
  600. $agentid = isset($agentbrokerarr[0]) ? $agentbrokerarr[0] : 0;
  601. if (!empty($agentid)) {
  602. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  603. $map[] = ['brokerid', 'in', $brokeridarr];
  604. $map[] = ['brokerid', '<>', 0];
  605. }
  606. $brokerid = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
  607. if (!empty($brokerid)) {
  608. $map[] = ['brokerid', '=', $brokerid];
  609. }
  610. $status = input('status/d');
  611. if (!empty($status)) {
  612. $map[] = ['status', '=', $status];
  613. }
  614. $authstatus = input('authstatus/d');
  615. if (!empty($authstatus)) {
  616. $map[] = ['authstatus', '=', $authstatus];
  617. }
  618. $followstatus = input('followstatus/d');
  619. if (!empty($followstatus)) {
  620. $map[] = ['followstatus', '=', $followstatus];
  621. }
  622. $xlsData = UserModel::with(['userGroups', 'broker' => ['agent', 'worker']])->withCount('userPart')->where($map)->order('id', 'desc')->append(['status_text', 'isvip_text', 'authstatus_text', 'followstatus_text'])->select()->toArray();
  623. $xlsCell = [
  624. ['id', '表ID'],
  625. ['nickname', '昵称'],
  626. ['realname', '姓名'],
  627. ['mobile', '手机号'],
  628. ['integral', '可用积分'],
  629. ['inttotal', '累计积分'],
  630. ['status_text', '状态'],
  631. ['isvip_text', '是否VIP'],
  632. ['authstatus_text', '是否实名认证'],
  633. ['idcard', '身份证号'],
  634. ['gender', '性别', [1 => '男', 2 => '女']],
  635. ['birthday', '出生日期'],
  636. ['address', '现居住地'],
  637. ['education', '学历'],
  638. ['bankcard.openbank', '开户行'],
  639. ['bankcard.account', '账户名'],
  640. ['bankcard.number', '账户号'],
  641. ['followstatus_text', '跟进状态'],
  642. ['userGroups.title', '用户组'],
  643. ['broker.worker.title', '劳务公司'],
  644. ['broker.agent.title', '代理门店'],
  645. ['broker.title', '职业顾问'],
  646. ['user_part_count', '推广人数'],
  647. ['createtime', '注册时间'],
  648. ];
  649. export_excel("系统用户", $xlsCell, $xlsData);
  650. }
  651. public function setBroker()
  652. {
  653. $idarr = input('idarr/a');
  654. $setagentbroker = explode(",", input('setagentbroker/s'));
  655. $brokerid = isset($setagentbroker[1]) ? $setagentbroker[1] : 0;
  656. if (empty($brokerid)) {
  657. exit(json_encode([
  658. 'code' => 1,
  659. 'msg' => "请选择职业顾问。",
  660. ]));
  661. }
  662. UserModel::whereIn('id', $idarr)->update(['brokerid' => $brokerid]);
  663. exit(json_encode([
  664. 'code' => 0,
  665. 'msg' => "",
  666. ]));
  667. }
  668. public function delUser()
  669. {
  670. $idarr = input('idarr/a');
  671. UserAuthsModel::whereIn('userid', $idarr)->delete();
  672. UserModel::destroy($idarr);
  673. // $result = Db::name('user')->whereIn('id',$idarr)->update(['deletetime'=>time()]);
  674. exit(json_encode([
  675. 'code' => 0,
  676. 'msg' => "",
  677. ]));
  678. }
  679. public function editUser()
  680. {
  681. $id = input('id/d');
  682. $mobile = input('mobile/s');
  683. $vdata = [
  684. 'id' => $id,
  685. 'mobile' => $mobile,
  686. ];
  687. try {
  688. validate(UserValidate::class)->check($vdata);
  689. } catch (ValidateException $e) {
  690. exit(json_encode([
  691. 'code' => 1,
  692. 'msg' => $e->getError(),
  693. ]));
  694. }
  695. //手机号
  696. $check_user_where = [['mobile', '=', $mobile]];
  697. if (!empty($id)) {
  698. $check_user_where[] = ['id', '<>', $id];
  699. }
  700. $check_user = UserModel::where($check_user_where)->find();
  701. if (!empty($check_user)) {
  702. exit(json_encode([
  703. 'code' => 1,
  704. 'msg' => '手机号已存在',
  705. ]));
  706. }
  707. $address = input('address/s', "");
  708. $jobintention = input('jobintention/s', "");
  709. if (!$address) {
  710. exit(json_encode([
  711. 'code' => 1,
  712. 'msg' => "请填写居住地址。",
  713. ]));
  714. }
  715. if (!$jobintention) {
  716. exit(json_encode([
  717. 'code' => 1,
  718. 'msg' => "请填写意向岗位。",
  719. ]));
  720. }
  721. $agentbrokerarr = explode(",", input('agentbroker/s'));
  722. $brokerid = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
  723. $data = [
  724. 'groupsid' => input('groupsid/d', 0),
  725. 'brokerid' => $brokerid,
  726. 'nickname' => input('nickname/s', ""),
  727. 'avatar' => input('avatar/s', ""),
  728. 'realname' => input('realname/s', ""),
  729. 'mobile' => $mobile,
  730. 'inttotal' => input('inttotal/d', 0),
  731. 'status' => input('status/d', 1),
  732. 'isvip' => input('isvip/d', 1),
  733. 'authstatus' => input('authstatus/d', 1),
  734. 'authremark' => input('authremark/s', ""),
  735. 'idcardzpic' => input('idcardzpic/s', ""),
  736. 'idcardfpic' => input('idcardfpic/s', ""),
  737. 'idcard' => input('idcard/s', ""),
  738. 'gender' => input('gender/d', 1),
  739. 'birthday' => input('birthday/s', ""),
  740. 'address' => $address,
  741. 'education' => input('education/s', ""),
  742. 'createtime' => input('createtime/s', ""),
  743. 'jobintention' => $jobintention,
  744. 'workexperience' => input('workexperience/s', ""),
  745. 'eduexperience' => input('eduexperience/s', ""),
  746. 'followstatus' => input('followstatus/d', 1),
  747. 'bankcard' => input('bankcard/a', []),
  748. ];
  749. $password = input('password/s');
  750. if (empty($id)) {
  751. $data['integral'] = 0;
  752. $data['wxampcode'] = '';
  753. $user = UserModel::create($data);
  754. $auths = UserAuthsModel::create([
  755. 'userid' => $user->id,
  756. 'identitytype' => "mobile",
  757. 'identifier' => $mobile,
  758. 'password' => empty($password) ? md5("123456789") : md5($password),
  759. 'logintime' => time(),
  760. 'loginip' => $_SERVER['SERVER_ADDR'],
  761. 'wxampcode' => "",
  762. ]);
  763. } else {
  764. $data['id'] = $id;
  765. $user = UserModel::update($data);
  766. $adata = ['identifier' => $mobile];
  767. if (!empty($password)) {
  768. $adata['password'] = md5($password);
  769. }
  770. UserAuthsModel::update($adata, ['userid' => $id, 'identitytype' => 'mobile']);
  771. }
  772. exit(json_encode([
  773. 'code' => 0,
  774. ]));
  775. }
  776. // 用户组
  777. public function groupsList()
  778. {
  779. return view('user/groupslist');
  780. }
  781. public function groupsForm()
  782. {
  783. $id = input('id/d, 0');
  784. $groups = UserGroupsModel::findOrEmpty($id);
  785. return view('user/groupsform', [
  786. 'groups' => $groups,
  787. ]);
  788. }
  789. public function listGroups()
  790. {
  791. $limit = input('limit');
  792. $page = input('page');
  793. $list = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->limit($limit)->page($page)->append(['isdefault_text'])->select();
  794. $count = UserGroupsModel::count();
  795. if ($count == 0) {
  796. exit(json_encode([
  797. 'code' => 1,
  798. 'msg' => "未查询到数据",
  799. ]));
  800. }
  801. exit(json_encode([
  802. 'code' => 0,
  803. 'msg' => "",
  804. 'count' => $count,
  805. 'data' => $list,
  806. ]));
  807. }
  808. public function editGroups()
  809. {
  810. $id = input('id/d');
  811. if (empty($id)) {
  812. $groups = UserGroupsModel::create([
  813. 'title' => input('title/s'),
  814. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  815. ]);
  816. } else {
  817. $administer = UserGroupsModel::find($id);
  818. $administer->save([
  819. 'title' => input('title/s'),
  820. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  821. ]);
  822. }
  823. exit(json_encode([
  824. 'code' => 0,
  825. ]));
  826. }
  827. public function delGroups()
  828. {
  829. $access_admin = session('access_admin');
  830. $password = input('password');
  831. if ($access_admin['password'] !== md5($password)) {
  832. exit(json_encode([
  833. 'code' => 1,
  834. 'msg' => "操作密码验证失败",
  835. ]));
  836. }
  837. $idarr = input('idarr/a');
  838. UserGroupsModel::whereIn('id', $idarr)->delete();
  839. exit(json_encode([
  840. 'code' => 0,
  841. 'msg' => "",
  842. ]));
  843. }
  844. // 参数设置
  845. public function param()
  846. {
  847. $param = UserParamModel::where(1)->findOrEmpty();
  848. return view('user/param', [
  849. 'param' => $param,
  850. ]);
  851. }
  852. public function editParam()
  853. {
  854. $param = UserParamModel::where(1)->findOrEmpty();
  855. $data = [
  856. 'redmoney' => input('redmoney/d', 0),
  857. 'usernumber' => input('usernumber/d', 0),
  858. 'shareintegral' => input('shareintegral/d', 0),
  859. 'postintegral' => input('postintegral/d', 0),
  860. 'inttomoney' => input('inttomoney/d', 0),
  861. 'minintegral' => input('minintegral/d', 0),
  862. 'intrecharge' => input('intrecharge/d', 0),
  863. 'picregworker' => input('picregworker/s', ""),
  864. 'intregworker' => input('intregworker/d', 0),
  865. ];
  866. if ($param->isEmpty()) {
  867. UserParamModel::create($data);
  868. } else {
  869. $data['id'] = $param->id;
  870. UserParamModel::update($data);
  871. }
  872. exit(json_encode([
  873. 'code' => 0,
  874. 'msg' => "",
  875. ]));
  876. }
  877. // 用户组
  878. public function willList()
  879. {
  880. return view('user/willlist');
  881. }
  882. public function willForm()
  883. {
  884. $id = input('id/d, 0');
  885. $will = UserWill::findOrEmpty($id);
  886. return view('user/willform', [
  887. 'will' => $will,
  888. ]);
  889. }
  890. public function listwill()
  891. {
  892. $limit = input('limit');
  893. $page = input('page');
  894. $list = UserWill::order(['isdefault' => 'desc', 'id' => 'asc'])->limit($limit)->page($page)->append(['isdefault_text'])->select();
  895. $count = UserWill::count();
  896. if ($count == 0) {
  897. exit(json_encode([
  898. 'code' => 1,
  899. 'msg' => "未查询到数据",
  900. ]));
  901. }
  902. exit(json_encode([
  903. 'code' => 0,
  904. 'msg' => "",
  905. 'count' => $count,
  906. 'data' => $list,
  907. ]));
  908. }
  909. public function editwill()
  910. {
  911. $id = input('id/d');
  912. if (empty($id)) {
  913. UserWill::create([
  914. 'title' => input('title/s'),
  915. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  916. ]);
  917. } else {
  918. $administer = UserWill::find($id);
  919. $administer->save([
  920. 'title' => input('title/s'),
  921. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  922. ]);
  923. }
  924. exit(json_encode([
  925. 'code' => 0,
  926. ]));
  927. }
  928. public function delwill()
  929. {
  930. $access_admin = session('access_admin');
  931. $password = input('password');
  932. if ($access_admin['password'] !== md5($password)) {
  933. exit(json_encode([
  934. 'code' => 1,
  935. 'msg' => "操作密码验证失败",
  936. ]));
  937. }
  938. $idarr = input('idarr/a');
  939. UserWill::whereIn('id', $idarr)->delete();
  940. exit(json_encode([
  941. 'code' => 0,
  942. 'msg' => "",
  943. ]));
  944. }
  945. public function import()
  946. {
  947. $data = ['nickname', 'gender', 'mobile', 'education', 'birthday', 'workexperience', 'jobintention',
  948. 'com_cate', 'emp_time', 'address', 'eduexperience'];
  949. $list = importExecl('2.xls', $data, 1);
  950. $data = [];
  951. $gender = ['男' => 1, '女' => 2];
  952. $education = ['初中' => 1, '高中' => 2, '中技' => 3, '中专' => 4, '大专' => 5, '本科' => 6, '硕士' => 7, '博士' => 8];
  953. $workexperience = ['无经验' => 1, '一年以下' => 2, '1-3年' => 3, '3-5年' => 4, '5-10年' => 5, '10年以上' => 6];
  954. $jobintention = ['长期工' => 1, '临时工' => 3];
  955. $rensheCode = RensheCode::where('type', 'emp_time')->column('code', 'name');
  956. $cateList = ComjobsCateModel::column('id', 'title');
  957. foreach ($list as $v) {
  958. $item = [];
  959. $item['nickname'] = $item['realname'] = $v['nickname'];
  960. $item['gender'] = $gender[$v['gender']];
  961. $item['mobile'] = $v['mobile'];
  962. $item['education'] = $education[$v['education']];
  963. $item['birthday'] = date('Y-m-d', strtotime($v['birthday']));
  964. if (empty($workexperience[$v['workexperience']])) {
  965. halt($v['workexperience']);
  966. }
  967. $item['workexperience'] = $workexperience[$v['workexperience']];
  968. $item['jobintention'] = $jobintention[$v['jobintention']];
  969. $item['com_cate'] = [];
  970. if (!empty($v['com_cate'])) {
  971. $com_cate = explode(',', str_replace(',', ',', $v['com_cate']));
  972. foreach ($com_cate as $cate) {
  973. if (!empty($cateList[$cate])) {
  974. $item['com_cate'][] = $cate;
  975. }
  976. }
  977. }
  978. $item['emp_time'] = [];
  979. if (!empty($v['emp_time'])) {
  980. $emp_time = explode(',', str_replace(',', ',', $v['emp_time']));
  981. foreach ($emp_time as $time) {
  982. if (!empty($rensheCode[$time])) {
  983. $item['emp_time'][] = $time;
  984. }
  985. }
  986. }
  987. $item['address'] = $v['address'] ?: '';
  988. $item['eduexperience'] = $v['eduexperience'] ?: '';
  989. $item['groupsid'] = 2;
  990. $item['status'] = 2;
  991. $item['authstatus'] = 3;
  992. $item['createtime'] = time();
  993. $data[] = $item;
  994. }
  995. foreach ($data as $v) {
  996. UserModel::create($v);
  997. }
  998. return '成功';
  999. }
  1000. }