User.php 36 KB

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