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\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. 'taskimage' => input('taskimage/s', ''),
  882. ];
  883. if ($param->isEmpty()) {
  884. UserParamModel::create($data);
  885. } else {
  886. $data['id'] = $param->id;
  887. UserParamModel::update($data);
  888. }
  889. exit(json_encode([
  890. 'code' => 0,
  891. 'msg' => "",
  892. ]));
  893. }
  894. // 用户组
  895. public function willList()
  896. {
  897. return view('user/willlist');
  898. }
  899. public function willForm()
  900. {
  901. $id = input('id/d, 0');
  902. $will = UserWill::findOrEmpty($id);
  903. return view('user/willform', [
  904. 'will' => $will,
  905. ]);
  906. }
  907. public function listwill()
  908. {
  909. $limit = input('limit');
  910. $page = input('page');
  911. $list = UserWill::order(['isdefault' => 'desc', 'id' => 'asc'])->limit($limit)->page($page)->append(['isdefault_text'])->select();
  912. $count = UserWill::count();
  913. if ($count == 0) {
  914. exit(json_encode([
  915. 'code' => 1,
  916. 'msg' => "未查询到数据",
  917. ]));
  918. }
  919. exit(json_encode([
  920. 'code' => 0,
  921. 'msg' => "",
  922. 'count' => $count,
  923. 'data' => $list,
  924. ]));
  925. }
  926. public function editwill()
  927. {
  928. $id = input('id/d');
  929. if (empty($id)) {
  930. UserWill::create([
  931. 'title' => input('title/s'),
  932. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  933. ]);
  934. } else {
  935. $administer = UserWill::find($id);
  936. $administer->save([
  937. 'title' => input('title/s'),
  938. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  939. ]);
  940. }
  941. exit(json_encode([
  942. 'code' => 0,
  943. ]));
  944. }
  945. public function delwill()
  946. {
  947. $access_admin = session('access_admin');
  948. $password = input('password');
  949. if ($access_admin['password'] !== md5($password)) {
  950. exit(json_encode([
  951. 'code' => 1,
  952. 'msg' => "操作密码验证失败",
  953. ]));
  954. }
  955. $idarr = input('idarr/a');
  956. UserWill::whereIn('id', $idarr)->delete();
  957. exit(json_encode([
  958. 'code' => 0,
  959. 'msg' => "",
  960. ]));
  961. }
  962. public function importView()
  963. {
  964. return view('user/importview');
  965. }
  966. public function import()
  967. {
  968. $file_url = input('file_url/s', "");
  969. if (!file_exists($file_url)) {
  970. exit(json_encode([
  971. 'code' => 1,
  972. 'msg' => "文件不存在",
  973. ]));
  974. }
  975. $service = new UserService();
  976. $res = $service->importComjobs($file_url);
  977. if (empty($res['code'])) {
  978. exit(json_encode([
  979. 'code' => 1,
  980. 'msg' => $res['msg'],
  981. ]));
  982. }
  983. exit(json_encode(['code' => 0]));
  984. }
  985. }