User.php 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  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\UserService;
  18. use app\common\validate\User as UserValidate;
  19. use think\exception\ValidateException;
  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. UserFollowModel::create([
  44. 'userid' => $userid,
  45. 'ftype' => input('ftype/s', ""),
  46. 'remark' => input('remark/s', ""),
  47. 'createtime' => time(),
  48. ]);
  49. $followstatus = input('followstatus/d', 1);
  50. $user->save([
  51. 'followstatus' => $followstatus,
  52. ]);
  53. exit(json_encode([
  54. 'code' => 0,
  55. ]));
  56. }
  57. // 邀请排行榜
  58. public function rankList()
  59. {
  60. return view('user/ranklist');
  61. }
  62. public function rankForm()
  63. {
  64. $id = input('id/d');
  65. $rank = UserRankModel::findOrEmpty($id);
  66. return view('user/rankform', [
  67. 'rank' => $rank,
  68. ]);
  69. }
  70. public function editRank()
  71. {
  72. $id = input('id/d');
  73. $rank = UserRankModel::findOrEmpty($id);
  74. $rank->save([
  75. 'realname' => input('realname/s'),
  76. 'mobile' => input('mobile/s'),
  77. 'partnumber' => input('partnumber/d', 0),
  78. ]);
  79. exit(json_encode([
  80. 'code' => 0,
  81. ]));
  82. }
  83. public function fieldRank()
  84. {
  85. $id = input('id/d', 0);
  86. $rank = UserRankModel::findOrEmpty($id);
  87. if ($rank->isEmpty()) {
  88. exit(json_encode([
  89. 'code' => 1,
  90. 'msg' => "信息不存在",
  91. ]));
  92. } else {
  93. $rank->save([
  94. input('field/s') => input('value'),
  95. ]);
  96. }
  97. exit(json_encode([
  98. 'code' => 0,
  99. ]));
  100. }
  101. public function listRank()
  102. {
  103. $limit = input('limit');
  104. $page = input('page');
  105. $map = [];
  106. $list = UserRankModel::where($map)->order('partnumber', 'desc')->limit($limit)->page($page)->select();
  107. $count = UserRankModel::where($map)->count();
  108. if ($count == 0) {
  109. exit(json_encode([
  110. 'code' => 1,
  111. 'msg' => "未查询到数据",
  112. ]));
  113. }
  114. exit(json_encode([
  115. 'code' => 0,
  116. 'msg' => "",
  117. 'count' => $count,
  118. 'data' => $list,
  119. ]));
  120. }
  121. public function delRank()
  122. {
  123. $idarr = input('idarr/a');
  124. UserRankModel::whereIn('id', $idarr)->delete();
  125. exit(json_encode([
  126. 'code' => 0,
  127. 'msg' => "",
  128. ]));
  129. }
  130. // 邀请记录
  131. public function partList()
  132. {
  133. return view('user/partlist');
  134. }
  135. public function listPart()
  136. {
  137. $limit = input('limit');
  138. $page = input('page');
  139. $map = [];
  140. $keywords = input('keywords/s', "");
  141. $status = input('status/d', 0);
  142. if (!empty($status)) {
  143. $map[] = ['UserPart.status', '=', $status];
  144. }
  145. $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();
  146. $count = UserPartModel::hasWhere('puser', [['realname|mobile', 'like', '%' . $keywords . '%', 'or']])->where($map)->count();
  147. if ($count == 0) {
  148. exit(json_encode([
  149. 'code' => 1,
  150. 'msg' => "未查询到数据",
  151. ]));
  152. }
  153. exit(json_encode([
  154. 'code' => 0,
  155. 'msg' => "",
  156. 'count' => $count,
  157. 'data' => $list,
  158. ]));
  159. }
  160. public function exportPart()
  161. {
  162. $map = [];
  163. $keywords = input('keywords/s', "");
  164. $status = input('status/d', 0);
  165. if (!empty($status)) {
  166. $map[] = ['UserPart.status', '=', $status];
  167. }
  168. $xlsData = UserPartModel::hasWhere('puser', [['realname|mobile', 'like', '%' . $keywords . '%', 'or']])->with(['puser', 'user'])->where($map)->order('id', 'desc')->select()->toArray();
  169. $xlsCell = [
  170. ['id', '表ID'],
  171. ['puser.nickname', '邀请人昵称'],
  172. ['puser.realname', '邀请人姓名'],
  173. ['puser.mobile', '邀请人手机号'],
  174. ['puser.bankcard.openbank', '邀请人开户行'],
  175. ['puser.bankcard.account', '邀请人帐户名'],
  176. ['puser.bankcard.number', '邀请人账户号'],
  177. ['user.nickname', '被邀请人昵称'],
  178. ['user.realname', '被邀请人姓名'],
  179. ['user.mobile', '被邀请人手机号'],
  180. ['status', '状态', [1 => '未入职', 2 => '已入职', 3 => '已发放']],
  181. ['redmoney', '奖金金额'],
  182. ['createtime', '推荐时间'],
  183. ];
  184. export_excel("系统用户", $xlsCell, $xlsData);
  185. }
  186. public function fieldPart()
  187. {
  188. $id = input('id/d', 0);
  189. $part = UserPartModel::findOrEmpty($id);
  190. if ($part->isEmpty()) {
  191. exit(json_encode([
  192. 'code' => 1,
  193. 'msg' => "信息不存在",
  194. ]));
  195. } else {
  196. $part->save([
  197. input('field/s') => input('value'),
  198. ]);
  199. }
  200. exit(json_encode([
  201. 'code' => 0,
  202. ]));
  203. }
  204. public function partForm()
  205. {
  206. $id = input('id/d');
  207. $part = UserPartModel::with(['puser', 'user'])->findOrEmpty($id);
  208. return view('user/partform', [
  209. 'part' => $part,
  210. ]);
  211. }
  212. public function editPart()
  213. {
  214. $id = input('id/d');
  215. $part = UserPartModel::findOrEmpty($id);
  216. $part->save([
  217. 'status' => input('status/d', 1),
  218. 'redmoney' => input('redmoney/d', 0),
  219. ]);
  220. exit(json_encode([
  221. 'code' => 0,
  222. ]));
  223. }
  224. public function delPart()
  225. {
  226. $idarr = input('idarr/a');
  227. UserPartModel::whereIn('id', $idarr)->delete();
  228. exit(json_encode([
  229. 'code' => 0,
  230. 'msg' => "",
  231. ]));
  232. }
  233. // 用户积分
  234. public function integralList()
  235. {
  236. return view('user/integrallist');
  237. }
  238. public function listIntegral()
  239. {
  240. $limit = input('limit');
  241. $page = input('page');
  242. $map = [];
  243. $keywords = input('keywords/s', "");
  244. $itype = input('itype/d', 0);
  245. if (!empty($itype)) {
  246. $map[] = ['itype', '=', $itype];
  247. }
  248. $status = input('status/d', 0);
  249. if (!empty($status)) {
  250. $map[] = ['status', '=', $status];
  251. }
  252. $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']);
  253. $count = UserIntegralModel::hasWhere('user', [['realname|mobile', 'like', '%' . $keywords . '%', 'or']])->where($map)->count();
  254. if ($count == 0) {
  255. exit(json_encode([
  256. 'code' => 1,
  257. 'msg' => "未查询到数据",
  258. ]));
  259. }
  260. exit(json_encode([
  261. 'code' => 0,
  262. 'msg' => "",
  263. 'count' => $count,
  264. 'data' => $list,
  265. ]));
  266. }
  267. public function exportIntegral()
  268. {
  269. $map = [];
  270. $keywords = input('keywords/s', "");
  271. $itype = input('itype/d', 0);
  272. if (!empty($itype)) {
  273. $map[] = ['itype', '=', $itype];
  274. }
  275. $xlsData = UserIntegralModel::hasWhere('user', [['realname|mobile', 'like', '%' . $keywords . '%', 'or']])->with(['user'])->where($map)->order('id', 'desc')->select()->append(['itype_text', 'status_text'])->toArray();
  276. $xlsCell = [
  277. ['id', '表ID'],
  278. ['user.nickname', '昵称'],
  279. ['user.realname', '姓名'],
  280. ['user.mobile', '手机号'],
  281. ['user.bankcard.openbank', '开户行'],
  282. ['user.bankcard.account', '帐户名'],
  283. ['user.bankcard.number', '账户号'],
  284. ['title', '积分标题'],
  285. ['itype_text', '类型'],
  286. ['status_text', '状态'],
  287. ['intvalue', '积分变更值'],
  288. ['intmoney', '积分金额'],
  289. ['remark', '备注'],
  290. ['createtime', '注册时间'],
  291. ];
  292. export_excel("用户积分", $xlsCell, $xlsData);
  293. }
  294. public function fieldIntegral()
  295. {
  296. $id = input('id/d', 0);
  297. $integral = UserIntegralModel::findOrEmpty($id);
  298. if ($integral->isEmpty()) {
  299. exit(json_encode([
  300. 'code' => 1,
  301. 'msg' => "信息不存在",
  302. ]));
  303. } else {
  304. $integral->save([
  305. input('field/s') => input('value'),
  306. ]);
  307. }
  308. exit(json_encode([
  309. 'code' => 0,
  310. ]));
  311. }
  312. public function integralUpdate()
  313. {
  314. $id = input('id/d', 0);
  315. $integral = UserIntegralModel::with('user')->findOrEmpty($id);
  316. return view('user/integralupdate', [
  317. 'integral' => $integral,
  318. ]);
  319. }
  320. public function updateIntegral()
  321. {
  322. $id = input('id/d', 0);
  323. $integral = UserIntegralModel::findOrEmpty($id);
  324. if ($integral->isEmpty()) {
  325. exit(json_encode([
  326. 'code' => 1,
  327. 'msg' => "用户积分记录不存在",
  328. ]));
  329. }
  330. $createtime = input('createtime/s', date("Y-m-d H:i:s"));
  331. $integral->save([
  332. 'title' => input('title/s', ""),
  333. 'intvalue' => input('intvalue/d', 0),
  334. 'intmoney' => input('intmoney/f', 0.00),
  335. 'remark' => input('remark/s', ""),
  336. 'itype' => input('itype/d', 1),
  337. 'status' => input('status/d', 1),
  338. 'createtime' => $createtime,
  339. 'yeartime' => date("Y", strtotime($createtime)),
  340. 'monthtime' => date("Ym", strtotime($createtime)),
  341. ]);
  342. exit(json_encode([
  343. 'code' => 0,
  344. ]));
  345. }
  346. public function statusIntegral()
  347. {
  348. $id = input('id/d');
  349. $integral = UserIntegralModel::where(['itype' => 3])->find($id);
  350. if ($integral == null) {
  351. exit(json_encode([
  352. 'code' => 1,
  353. 'msg' => "该记录非兑现类型",
  354. ]));
  355. } elseif ($integral->status == 1) {
  356. $integral->save([
  357. 'status' => 2,
  358. ]);
  359. } elseif ($integral->status == 2) {
  360. $integral->save([
  361. 'status' => 1,
  362. ]);
  363. } else {
  364. exit(json_encode([
  365. 'code' => 1,
  366. 'msg' => "该记录非兑现类型。",
  367. ]));
  368. }
  369. exit(json_encode([
  370. 'code' => 0,
  371. ]));
  372. }
  373. public function statusIntegralAll()
  374. {
  375. $idarr = input('idarr/a');
  376. UserIntegralModel::update(['status' => 2], ['status' => 1, 'itype' => 3, 'id' => $idarr]);
  377. exit(json_encode([
  378. 'code' => 0,
  379. 'msg' => "",
  380. ]));
  381. }
  382. public function delIntegral()
  383. {
  384. $idarr = input('idarr/a');
  385. UserIntegralModel::whereIn('id', $idarr)->delete();
  386. exit(json_encode([
  387. 'code' => 0,
  388. 'msg' => "",
  389. ]));
  390. }
  391. public function integralForm()
  392. {
  393. $userid = input('userid/d');
  394. $user = UserModel::findOrEmpty($userid);
  395. return view('user/integralform', [
  396. 'user' => $user,
  397. ]);
  398. }
  399. public function editIntegral()
  400. {
  401. $userid = input('userid/d');
  402. $user = UserModel::findOrEmpty($userid);
  403. $intvalue = input('intvalue/d', 0);
  404. if ($intvalue == 0) {
  405. exit(json_encode([
  406. 'code' => 1,
  407. 'msg' => "积分变更值不能为0",
  408. ]));
  409. }
  410. $data = [
  411. 'userid' => $userid,
  412. 'title' => input('title/s'),
  413. 'intvalue' => $intvalue,
  414. 'intmoney' => input('intmoney/s', 0.00),
  415. 'onlycontent' => "",
  416. 'remark' => input('remark/s'),
  417. 'itype' => input('itype/d'),
  418. 'status' => 2,
  419. 'createtime' => input('createtime/s'),
  420. 'yeartime' => date("Y"),
  421. 'monthtime' => date("Ym"),
  422. ];
  423. UserIntegralModel::create($data);
  424. $udata = [];
  425. $udata['integral'] = intval($user->integral) + $intvalue;
  426. $isinttotal = input('isinttotal/d', 0);
  427. if ($isinttotal == 1) {
  428. $udata['inttotal'] = intval($user->inttotal) + $intvalue;
  429. }
  430. $user->save($udata);
  431. exit(json_encode([
  432. 'code' => 0,
  433. ]));
  434. }
  435. // 用户授权
  436. public function authsList()
  437. {
  438. $userid = input('userid/d');
  439. return view('user/authslist', [
  440. 'userid' => $userid,
  441. ]);
  442. }
  443. public function listAuths()
  444. {
  445. $userid = input('userid/d');
  446. $list = UserAuthsModel::where('userid', $userid)->order('id', 'asc')->append(['identitytype_text'])->select();
  447. $count = UserAuthsModel::where('userid', $userid)->count();
  448. if ($count == 0) {
  449. exit(json_encode([
  450. 'code' => 1,
  451. 'msg' => "未查询到数据",
  452. ]));
  453. }
  454. exit(json_encode([
  455. 'code' => 0,
  456. 'msg' => "",
  457. 'count' => $count,
  458. 'data' => $list,
  459. ]));
  460. }
  461. public function delAuths()
  462. {
  463. $id = input('id/d');
  464. $auths = UserAuthsModel::find($id);
  465. if ($auths->identitytype == 'mobile') {
  466. exit(json_encode([
  467. 'code' => 1,
  468. 'msg' => "手机号授权方式不允许删除",
  469. ]));
  470. }
  471. $result = $auths->delete();
  472. if ($result) {
  473. exit(json_encode([
  474. 'code' => 0,
  475. ]));
  476. }
  477. exit(json_encode([
  478. 'code' => 1,
  479. 'msg' => "删除失败,请稍后重试",
  480. ]));
  481. }
  482. // 用户
  483. public function userPublic()
  484. {
  485. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  486. $agentlist = AgentModel::with('broker')->order(['id' => 'desc'])->select();
  487. return view('user/userpublic', [
  488. 'groupslist' => $groupslist,
  489. 'agentlist' => $agentlist,
  490. ]);
  491. }
  492. public function userList()
  493. {
  494. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  495. $agentlist = AgentModel::with('broker')->order(['id' => 'desc'])->select();
  496. return view('user/userlist', [
  497. 'groupslist' => $groupslist,
  498. 'agentlist' => $agentlist,
  499. ]);
  500. }
  501. public function userForm()
  502. {
  503. $id = input('id/d', 0);
  504. $user = UserModel::with(['broker'])->findOrEmpty($id);
  505. $agentlist = AgentModel::with('broker')->order(['id' => 'asc'])->select();
  506. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  507. $willlist = UserWill::select();
  508. $emptimelist = RensheCode::getList('emp_time');
  509. $communitylist = RensheCode::getList('community')->toArray();
  510. array_push($communitylist, ['code' => 0, 'id' => 0, 'name' => "不限"]);
  511. $comlist = ComjobsCateModel::select();
  512. return view('user/userform', [
  513. 'groupslist' => $groupslist,
  514. 'willlist' => $willlist,
  515. 'agentlist' => $agentlist,
  516. 'user' => $user,
  517. 'emptimelist' => $emptimelist,
  518. 'communitylist' => $communitylist,
  519. 'comlist' => $comlist,
  520. ]);
  521. }
  522. public function fieldUser()
  523. {
  524. $id = input('id/d', 0);
  525. $user = UserModel::findOrEmpty($id);
  526. if ($user->isEmpty()) {
  527. exit(json_encode([
  528. 'code' => 1,
  529. 'msg' => "信息不存在",
  530. ]));
  531. } else {
  532. $user->save([
  533. input('field/s') => input('value'),
  534. ]);
  535. }
  536. exit(json_encode([
  537. 'code' => 0,
  538. ]));
  539. }
  540. public function listUser()
  541. {
  542. $limit = input('limit');
  543. $page = input('page');
  544. $map = [];
  545. $keywords = input('keywords/s');
  546. if (!empty($keywords)) {
  547. $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
  548. }
  549. $groupsid = input('groupsid/d');
  550. if (!empty($groupsid)) {
  551. $map[] = ['groupsid', '=', $groupsid];
  552. }
  553. $ispublic = input('ispublic/d', 0);
  554. if ($ispublic == 0) {
  555. $agentbrokerarr = explode(",", input('agentbroker/s'));
  556. $agentid = isset($agentbrokerarr[0]) ? $agentbrokerarr[0] : 0;
  557. if (!empty($agentid)) {
  558. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  559. $map[] = ['brokerid', 'in', $brokeridarr];
  560. $map[] = ['brokerid', '<>', 0];
  561. }
  562. $brokerid = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
  563. if (!empty($brokerid)) {
  564. $map[] = ['brokerid', '=', $brokerid];
  565. }
  566. } else {
  567. $map[] = ['brokerid', '=', 0];
  568. }
  569. $status = input('status/d');
  570. if (!empty($status)) {
  571. $map[] = ['status', '=', $status];
  572. }
  573. $authstatus = input('authstatus/d');
  574. if (!empty($authstatus)) {
  575. $map[] = ['authstatus', '=', $authstatus];
  576. }
  577. $followstatus = input('followstatus/d');
  578. if (!empty($followstatus)) {
  579. $map[] = ['followstatus', '=', $followstatus];
  580. }
  581. $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();
  582. $count = UserModel::where($map)->count();
  583. if ($count == 0) {
  584. exit(json_encode([
  585. 'code' => 1,
  586. 'msg' => "未查询到数据",
  587. ]));
  588. }
  589. exit(json_encode([
  590. 'code' => 0,
  591. 'msg' => "",
  592. 'count' => $count,
  593. 'data' => $list,
  594. ]));
  595. }
  596. public function exportUser()
  597. {
  598. $map = [];
  599. $keywords = input('keywords/s');
  600. if (!empty($keywords)) {
  601. $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
  602. }
  603. $groupsid = input('groupsid/d');
  604. if (!empty($groupsid)) {
  605. $map[] = ['groupsid', '=', $groupsid];
  606. }
  607. $agentbrokerarr = explode(",", input('agentbroker/s'));
  608. $agentid = isset($agentbrokerarr[0]) ? $agentbrokerarr[0] : 0;
  609. if (!empty($agentid)) {
  610. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  611. $map[] = ['brokerid', 'in', $brokeridarr];
  612. $map[] = ['brokerid', '<>', 0];
  613. }
  614. $brokerid = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
  615. if (!empty($brokerid)) {
  616. $map[] = ['brokerid', '=', $brokerid];
  617. }
  618. $status = input('status/d');
  619. if (!empty($status)) {
  620. $map[] = ['status', '=', $status];
  621. }
  622. $authstatus = input('authstatus/d');
  623. if (!empty($authstatus)) {
  624. $map[] = ['authstatus', '=', $authstatus];
  625. }
  626. $followstatus = input('followstatus/d');
  627. if (!empty($followstatus)) {
  628. $map[] = ['followstatus', '=', $followstatus];
  629. }
  630. $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();
  631. $xlsCell = [
  632. ['id', '表ID'],
  633. ['nickname', '昵称'],
  634. ['realname', '姓名'],
  635. ['mobile', '手机号'],
  636. ['integral', '可用积分'],
  637. ['inttotal', '累计积分'],
  638. ['status_text', '状态'],
  639. ['isvip_text', '是否VIP'],
  640. ['authstatus_text', '是否实名认证'],
  641. ['idcard', '身份证号'],
  642. ['gender', '性别', [1 => '男', 2 => '女']],
  643. ['birthday', '出生日期'],
  644. ['address', '现居住地'],
  645. ['education', '学历'],
  646. ['bankcard.openbank', '开户行'],
  647. ['bankcard.account', '账户名'],
  648. ['bankcard.number', '账户号'],
  649. ['followstatus_text', '跟进状态'],
  650. ['userGroups.title', '用户组'],
  651. ['broker.worker.title', '劳务公司'],
  652. ['broker.agent.title', '代理门店'],
  653. ['broker.title', '职业顾问'],
  654. ['user_part_count', '推广人数'],
  655. ['createtime', '注册时间'],
  656. ];
  657. export_excel("系统用户", $xlsCell, $xlsData);
  658. }
  659. public function setBroker()
  660. {
  661. $idarr = input('idarr/a');
  662. $setagentbroker = explode(",", input('setagentbroker/s'));
  663. $brokerid = isset($setagentbroker[1]) ? $setagentbroker[1] : 0;
  664. if (empty($brokerid)) {
  665. exit(json_encode([
  666. 'code' => 1,
  667. 'msg' => "请选择职业顾问。",
  668. ]));
  669. }
  670. UserModel::whereIn('id', $idarr)->update(['brokerid' => $brokerid]);
  671. exit(json_encode([
  672. 'code' => 0,
  673. 'msg' => "",
  674. ]));
  675. }
  676. public function delUser()
  677. {
  678. $idarr = input('idarr/a');
  679. UserModel::destroy($idarr);
  680. event('userDel',$idarr);
  681. exit(json_encode([
  682. 'code' => 0,
  683. 'msg' => "",
  684. ]));
  685. }
  686. public function editUser()
  687. {
  688. $id = input('id/d');
  689. $mobile = input('mobile/s');
  690. $vdata = [
  691. 'id' => $id,
  692. 'mobile' => $mobile,
  693. ];
  694. try {
  695. validate(UserValidate::class)->check($vdata);
  696. } catch (ValidateException $e) {
  697. exit(json_encode([
  698. 'code' => 1,
  699. 'msg' => $e->getError(),
  700. ]));
  701. }
  702. //手机号
  703. $check_user_where = [['mobile', '=', $mobile]];
  704. if (!empty($id)) {
  705. $check_user_where[] = ['id', '<>', $id];
  706. }
  707. $check_user = UserModel::where($check_user_where)->find();
  708. if (!empty($check_user)) {
  709. exit(json_encode([
  710. 'code' => 1,
  711. 'msg' => '手机号已存在',
  712. ]));
  713. }
  714. $address = input('address/s', "");
  715. $jobintention = input('jobintention/s', "");
  716. $agentbrokerarr = explode(",", input('agentbroker/s'));
  717. $brokerid = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
  718. $data = [
  719. 'groupsid' => input('groupsid/d', 0),
  720. 'brokerid' => $brokerid,
  721. 'nickname' => input('nickname/s', ""),
  722. 'avatar' => input('avatar/s', ""),
  723. 'realname' => input('realname/s', ""),
  724. 'mobile' => $mobile,
  725. 'inttotal' => input('inttotal/d', 0),
  726. 'status' => input('status/d', 1),
  727. 'isvip' => input('isvip/d', 1),
  728. 'authstatus' => input('authstatus/d', 1),
  729. 'authremark' => input('authremark/s', ""),
  730. 'idcardzpic' => input('idcardzpic/s', ""),
  731. 'idcardfpic' => input('idcardfpic/s', ""),
  732. 'idcard' => input('idcard/s', ""),
  733. 'gender' => input('gender/d', 1),
  734. 'birthday' => input('birthday/s', ""),
  735. 'address' => $address,
  736. 'education' => input('education/s', ""),
  737. 'createtime' => input('createtime/s', ""),
  738. 'jobintention' => $jobintention,
  739. 'workexperience' => input('workexperience/s', ""),
  740. 'eduexperience' => input('eduexperience/s', ""),
  741. 'followstatus' => input('followstatus/d', 1),
  742. 'bankcard' => input('bankcard/a', []),
  743. 'emp_time' => array_values(input('emp_time/a', [])),
  744. 'work_place' => array_values(input('work_place/a', [])),
  745. 'com_cate_type' => input('com_cate_type/d', 1),
  746. 'com_cate' => array_values(input('com_cate/a', "")),
  747. 'com_cate_other' => input('com_cate_other/s', ""),
  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 importView()
  946. {
  947. return view('user/importview');
  948. }
  949. public function import()
  950. {
  951. $file_url = input('file_url/s', "");
  952. if (!file_exists($file_url)) {
  953. exit(json_encode([
  954. 'code' => 1,
  955. 'msg' => "文件不存在",
  956. ]));
  957. }
  958. $service = new UserService();
  959. $res = $service->importComjobs($file_url);
  960. if (empty($res['code'])) {
  961. exit(json_encode([
  962. 'code' => 1,
  963. 'msg' => $res['msg'],
  964. ]));
  965. }
  966. exit(json_encode(['code' => 0]));
  967. }
  968. }