User.php 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  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. $address = input('address/s', "");
  696. $jobintention = input('jobintention/s', "");
  697. if (!$address) {
  698. exit(json_encode([
  699. 'code' => 1,
  700. 'msg' => "请填写居住地址。",
  701. ]));
  702. }
  703. if (!$jobintention) {
  704. exit(json_encode([
  705. 'code' => 1,
  706. 'msg' => "请填写意向岗位。",
  707. ]));
  708. }
  709. $agentbrokerarr = explode(",", input('agentbroker/s'));
  710. $brokerid = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
  711. $data = [
  712. 'groupsid' => input('groupsid/d', 0),
  713. 'brokerid' => $brokerid,
  714. 'nickname' => input('nickname/s', ""),
  715. 'avatar' => input('avatar/s', ""),
  716. 'realname' => input('realname/s', ""),
  717. 'mobile' => $mobile,
  718. 'inttotal' => input('inttotal/d', 0),
  719. 'status' => input('status/d', 1),
  720. 'isvip' => input('isvip/d', 1),
  721. 'authstatus' => input('authstatus/d', 1),
  722. 'authremark' => input('authremark/s', ""),
  723. 'idcardzpic' => input('idcardzpic/s', ""),
  724. 'idcardfpic' => input('idcardfpic/s', ""),
  725. 'idcard' => input('idcard/s', ""),
  726. 'gender' => input('gender/d', 1),
  727. 'birthday' => input('birthday/s', ""),
  728. 'address' => $address,
  729. 'education' => input('education/s', ""),
  730. 'createtime' => input('createtime/s', ""),
  731. 'jobintention' => $jobintention,
  732. 'workexperience' => input('workexperience/s', ""),
  733. 'eduexperience' => input('eduexperience/s', ""),
  734. 'followstatus' => input('followstatus/d', 1),
  735. 'bankcard' => input('bankcard/a', []),
  736. ];
  737. $password = input('password/s');
  738. if (empty($id)) {
  739. $data['integral'] = 0;
  740. $data['wxampcode'] = '';
  741. $user = UserModel::create($data);
  742. $auths = UserAuthsModel::create([
  743. 'userid' => $user->id,
  744. 'identitytype' => "mobile",
  745. 'identifier' => $mobile,
  746. 'password' => empty($password) ? md5("123456789") : md5($password),
  747. 'logintime' => time(),
  748. 'loginip' => $_SERVER['SERVER_ADDR'],
  749. 'wxampcode' => "",
  750. ]);
  751. } else {
  752. $data['id'] = $id;
  753. $user = UserModel::update($data);
  754. $adata = ['identifier' => $mobile];
  755. if (!empty($password)) {
  756. $adata['password'] = md5($password);
  757. }
  758. UserAuthsModel::update($adata, ['userid' => $id, 'identitytype' => 'mobile']);
  759. }
  760. exit(json_encode([
  761. 'code' => 0,
  762. ]));
  763. }
  764. // 用户组
  765. public function groupsList()
  766. {
  767. return view('user/groupslist');
  768. }
  769. public function groupsForm()
  770. {
  771. $id = input('id/d, 0');
  772. $groups = UserGroupsModel::findOrEmpty($id);
  773. return view('user/groupsform', [
  774. 'groups' => $groups,
  775. ]);
  776. }
  777. public function listGroups()
  778. {
  779. $limit = input('limit');
  780. $page = input('page');
  781. $list = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->limit($limit)->page($page)->append(['isdefault_text'])->select();
  782. $count = UserGroupsModel::count();
  783. if ($count == 0) {
  784. exit(json_encode([
  785. 'code' => 1,
  786. 'msg' => "未查询到数据",
  787. ]));
  788. }
  789. exit(json_encode([
  790. 'code' => 0,
  791. 'msg' => "",
  792. 'count' => $count,
  793. 'data' => $list,
  794. ]));
  795. }
  796. public function editGroups()
  797. {
  798. $id = input('id/d');
  799. if (empty($id)) {
  800. $groups = UserGroupsModel::create([
  801. 'title' => input('title/s'),
  802. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  803. ]);
  804. } else {
  805. $administer = UserGroupsModel::find($id);
  806. $administer->save([
  807. 'title' => input('title/s'),
  808. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  809. ]);
  810. }
  811. exit(json_encode([
  812. 'code' => 0,
  813. ]));
  814. }
  815. public function delGroups()
  816. {
  817. $access_admin = session('access_admin');
  818. $password = input('password');
  819. if ($access_admin['password'] !== md5($password)) {
  820. exit(json_encode([
  821. 'code' => 1,
  822. 'msg' => "操作密码验证失败",
  823. ]));
  824. }
  825. $idarr = input('idarr/a');
  826. UserGroupsModel::whereIn('id', $idarr)->delete();
  827. exit(json_encode([
  828. 'code' => 0,
  829. 'msg' => "",
  830. ]));
  831. }
  832. // 参数设置
  833. public function param()
  834. {
  835. $param = UserParamModel::where(1)->findOrEmpty();
  836. return view('user/param', [
  837. 'param' => $param,
  838. ]);
  839. }
  840. public function editParam()
  841. {
  842. $param = UserParamModel::where(1)->findOrEmpty();
  843. $data = [
  844. 'redmoney' => input('redmoney/d', 0),
  845. 'usernumber' => input('usernumber/d', 0),
  846. 'shareintegral' => input('shareintegral/d', 0),
  847. 'postintegral' => input('postintegral/d', 0),
  848. 'inttomoney' => input('inttomoney/d', 0),
  849. 'minintegral' => input('minintegral/d', 0),
  850. 'intrecharge' => input('intrecharge/d', 0),
  851. 'picregworker' => input('picregworker/s', ""),
  852. 'intregworker' => input('intregworker/d', 0),
  853. ];
  854. if ($param->isEmpty()) {
  855. UserParamModel::create($data);
  856. } else {
  857. $data['id'] = $param->id;
  858. UserParamModel::update($data);
  859. }
  860. exit(json_encode([
  861. 'code' => 0,
  862. 'msg' => "",
  863. ]));
  864. }
  865. // 用户组
  866. public function willList()
  867. {
  868. return view('user/willlist');
  869. }
  870. public function willForm()
  871. {
  872. $id = input('id/d, 0');
  873. $will = UserWill::findOrEmpty($id);
  874. return view('user/willform', [
  875. 'will' => $will,
  876. ]);
  877. }
  878. public function listwill()
  879. {
  880. $limit = input('limit');
  881. $page = input('page');
  882. $list = UserWill::order(['isdefault' => 'desc', 'id' => 'asc'])->limit($limit)->page($page)->append(['isdefault_text'])->select();
  883. $count = UserWill::count();
  884. if ($count == 0) {
  885. exit(json_encode([
  886. 'code' => 1,
  887. 'msg' => "未查询到数据",
  888. ]));
  889. }
  890. exit(json_encode([
  891. 'code' => 0,
  892. 'msg' => "",
  893. 'count' => $count,
  894. 'data' => $list,
  895. ]));
  896. }
  897. public function editwill()
  898. {
  899. $id = input('id/d');
  900. if (empty($id)) {
  901. UserWill::create([
  902. 'title' => input('title/s'),
  903. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  904. ]);
  905. } else {
  906. $administer = UserWill::find($id);
  907. $administer->save([
  908. 'title' => input('title/s'),
  909. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  910. ]);
  911. }
  912. exit(json_encode([
  913. 'code' => 0,
  914. ]));
  915. }
  916. public function delwill()
  917. {
  918. $access_admin = session('access_admin');
  919. $password = input('password');
  920. if ($access_admin['password'] !== md5($password)) {
  921. exit(json_encode([
  922. 'code' => 1,
  923. 'msg' => "操作密码验证失败",
  924. ]));
  925. }
  926. $idarr = input('idarr/a');
  927. UserWill::whereIn('id', $idarr)->delete();
  928. exit(json_encode([
  929. 'code' => 0,
  930. 'msg' => "",
  931. ]));
  932. }
  933. public function import()
  934. {
  935. $data = ['nickname', 'gender', 'mobile', 'education', 'birthday', 'workexperience', 'jobintention',
  936. 'com_cate', 'emp_time', 'address', 'eduexperience'];
  937. $list = importExecl('2.xls', $data, 1);
  938. halt($list);
  939. $data = [];
  940. $gender = ['男' => 1, '女' => 2];
  941. $education = ['初中' => 1, '高中' => 2, '中技' => 3, '中专' => 4, '大专' => 5, '本科' => 6, '硕士' => 7, '博士' => 8];
  942. $workexperience = ['无经验' => 1, '一年以下' => 2, '1-3年' => 3, '3-5年' => 4, '5-10年' => 5, '10年以上' => 6];
  943. $jobintention = ['长期工' => 1, '临时工' => 3];
  944. $rensheCode = RensheCode::where('type', 'emp_time')->column('code', 'name');
  945. $cateList = ComjobsCateModel::column('id', 'title');
  946. foreach ($list as $v) {
  947. $item = [];
  948. $item['nickname'] = $item['realname'] = $v['nickname'];
  949. $item['gender'] = $gender[$v['gender']];
  950. $item['mobile'] = $v['mobile'];
  951. $item['education'] = $education[$v['education']];
  952. $item['birthday'] = date('Y-m-d', strtotime($v['birthday']));
  953. $item['workexperience'] = $workexperience[$v['workexperience']];
  954. $item['jobintention'] = $jobintention[$v['jobintention']];
  955. $item['com_cate'] = [];
  956. if (!empty($v['com_cate'])) {
  957. $com_cate = explode(',', str_replace(',', ',', $v['com_cate']));
  958. foreach ($com_cate as $cate) {
  959. if (!empty($cateList[$cate])) {
  960. $item['com_cate'][] = $cate;
  961. }
  962. }
  963. }
  964. $item['emp_time'] = [];
  965. if (!empty($v['emp_time'])) {
  966. $emp_time = explode(',', str_replace(',', ',', $v['emp_time']));
  967. foreach ($emp_time as $time) {
  968. if (!empty($rensheCode[$time])) {
  969. $item['emp_time'][] = $time;
  970. }
  971. }
  972. }
  973. $item['address'] = $v['address'];
  974. $item['eduexperience'] = $v['eduexperience'];
  975. $item['groupsid'] = 2;
  976. $item['status'] = 2;
  977. $item['authstatus'] = 3;
  978. $item['createtime'] = time();
  979. $data[] = $item;
  980. }
  981. foreach ($data as $v) {
  982. UserModel::create($v);
  983. }
  984. return '成功';
  985. }
  986. }