User.php 33 KB

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