User.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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\BalanceService;
  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, 'broker_channel' => 2]);
  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. 'skill_cert' => array_values(input('skill_cert/a', [])),
  754. ];
  755. $password = input('password/s');
  756. if (empty($id)) {
  757. $data['integral'] = 0;
  758. $data['wxampcode'] = '';
  759. $data['broker_channel'] = 2;
  760. $user = UserModel::create($data);
  761. UserAuthsModel::create([
  762. 'userid' => $user->id,
  763. 'identitytype' => "mobile",
  764. 'identifier' => $mobile,
  765. 'password' => empty($password) ? md5("123456789") : md5($password),
  766. 'logintime' => time(),
  767. 'loginip' => $_SERVER['SERVER_ADDR'],
  768. 'wxampcode' => "",
  769. ]);
  770. } else {
  771. $data['id'] = $id;
  772. $user = UserModel::find($id);
  773. if ($user['brokerid'] != $brokerid) {
  774. $data['broker_channel'] = 2;
  775. }
  776. UserModel::update($data);
  777. $adata = ['identifier' => $mobile];
  778. if (!empty($password)) {
  779. $adata['password'] = md5($password);
  780. }
  781. UserAuthsModel::update($adata, ['userid' => $id, 'identitytype' => 'mobile']);
  782. //实名认证积分
  783. $user = UserModel::where('id', $id)->find();
  784. if ($user['authstatus'] == 3 && $user['is_auth'] == 2) {
  785. $user->is_auth = 1;
  786. $user->save();
  787. /*$integralService = new IntegralService();
  788. $integralService->add($id, IntegralService::CERTIFICATION);*/
  789. //发放佣金
  790. $balanceService = new BalanceService();
  791. $balanceService->add($id, BalanceService::CERTIFICATION);
  792. }
  793. }
  794. exit(json_encode([
  795. 'code' => 0,
  796. ]));
  797. }
  798. // 用户组
  799. public function groupsList()
  800. {
  801. return view('user/groupslist');
  802. }
  803. public function groupsForm()
  804. {
  805. $id = input('id/d, 0');
  806. $groups = UserGroupsModel::findOrEmpty($id);
  807. return view('user/groupsform', [
  808. 'groups' => $groups,
  809. ]);
  810. }
  811. public function listGroups()
  812. {
  813. $limit = input('limit');
  814. $page = input('page');
  815. $list = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->limit($limit)->page($page)->append(['isdefault_text'])->select();
  816. $count = UserGroupsModel::count();
  817. if ($count == 0) {
  818. exit(json_encode([
  819. 'code' => 1,
  820. 'msg' => "未查询到数据",
  821. ]));
  822. }
  823. exit(json_encode([
  824. 'code' => 0,
  825. 'msg' => "",
  826. 'count' => $count,
  827. 'data' => $list,
  828. ]));
  829. }
  830. public function editGroups()
  831. {
  832. $id = input('id/d');
  833. if (empty($id)) {
  834. $groups = UserGroupsModel::create([
  835. 'title' => input('title/s'),
  836. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  837. ]);
  838. } else {
  839. $administer = UserGroupsModel::find($id);
  840. $administer->save([
  841. 'title' => input('title/s'),
  842. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  843. ]);
  844. }
  845. exit(json_encode([
  846. 'code' => 0,
  847. ]));
  848. }
  849. public function delGroups()
  850. {
  851. $access_admin = session('access_admin');
  852. $password = input('password');
  853. if ($access_admin['password'] !== md5($password)) {
  854. exit(json_encode([
  855. 'code' => 1,
  856. 'msg' => "操作密码验证失败",
  857. ]));
  858. }
  859. $idarr = input('idarr/a');
  860. UserGroupsModel::whereIn('id', $idarr)->delete();
  861. exit(json_encode([
  862. 'code' => 0,
  863. 'msg' => "",
  864. ]));
  865. }
  866. // 参数设置
  867. public function param()
  868. {
  869. $param = UserParamModel::where(1)->findOrEmpty();
  870. return view('user/param', [
  871. 'param' => $param,
  872. ]);
  873. }
  874. public function editParam()
  875. {
  876. $param = UserParamModel::where(1)->findOrEmpty();
  877. $data = [
  878. 'redmoney' => input('redmoney/d', 0),
  879. 'usernumber' => input('usernumber/d', 0),
  880. 'shareintegral' => input('shareintegral/d', 0),
  881. 'postintegral' => input('postintegral/d', 0),
  882. 'inttomoney' => input('inttomoney/d', 0),
  883. 'minintegral' => input('minintegral/d', 0),
  884. 'intrecharge' => input('intrecharge/d', 0),
  885. 'picregworker' => input('picregworker/s', ""),
  886. 'intregworker' => input('intregworker/d', 0),
  887. 'register' => input('register/d', 0),
  888. 'improveresume' => input('improveresume/d', 0),
  889. 'certification' => input('certification/d', 0),
  890. 'entry' => input('entry/d', 0),
  891. 'signin' => input('signin/d', 0),
  892. 'sharejob' => input('sharejob/d', 0),
  893. 'sharejobnum' => input('sharejobnum/d', 0),
  894. 'taskimage' => input('taskimage/s', ''),
  895. ];
  896. if ($param->isEmpty()) {
  897. UserParamModel::create($data);
  898. } else {
  899. $data['id'] = $param->id;
  900. UserParamModel::update($data);
  901. }
  902. exit(json_encode([
  903. 'code' => 0,
  904. 'msg' => "",
  905. ]));
  906. }
  907. // 提现设置
  908. public function getmoney()
  909. {
  910. $param = UserParamModel::where(1)->findOrEmpty();
  911. return view('user/getmoney', [
  912. 'getmoney' => $param['getmoney'],
  913. ]);
  914. }
  915. public function editGetmoney()
  916. {
  917. $param = UserParamModel::where(1)->findOrEmpty();
  918. $data = [
  919. 'getmoney' => input('getmoney/a', []),
  920. ];
  921. foreach ($data['getmoney'] as $v) {
  922. if ($v['money'] < 0.3) {
  923. exit(json_encode([
  924. 'code' => 1,
  925. 'msg' => "金额必须大于等于0.3",
  926. ]));
  927. }
  928. if ($v['num'] <= 0) {
  929. exit(json_encode([
  930. 'code' => 1,
  931. 'msg' => "次数必须大于等于0",
  932. ]));
  933. }
  934. }
  935. if ($param->isEmpty()) {
  936. UserParamModel::create($data);
  937. } else {
  938. $param->getmoney = $data['getmoney'];
  939. $param->save();
  940. }
  941. exit(json_encode([
  942. 'code' => 0,
  943. 'msg' => "",
  944. ]));
  945. }
  946. // 佣金设置
  947. public function commission()
  948. {
  949. $param = UserParamModel::where(1)->findOrEmpty();
  950. return view('user/commission', [
  951. 'commission' => $param['commission'],
  952. ]);
  953. }
  954. public function editCommission()
  955. {
  956. $param = UserParamModel::where(1)->findOrEmpty();
  957. $data = [
  958. 'commission' => input('commission/a', []),
  959. ];
  960. if ($param->isEmpty()) {
  961. UserParamModel::create($data);
  962. } else {
  963. $param->commission = $data['commission'];
  964. $param->save();
  965. }
  966. exit(json_encode([
  967. 'code' => 0,
  968. 'msg' => "",
  969. ]));
  970. }
  971. // 用户组
  972. public function willList()
  973. {
  974. return view('user/willlist');
  975. }
  976. public function willForm()
  977. {
  978. $id = input('id/d, 0');
  979. $will = UserWill::findOrEmpty($id);
  980. return view('user/willform', [
  981. 'will' => $will,
  982. ]);
  983. }
  984. public function listwill()
  985. {
  986. $limit = input('limit');
  987. $page = input('page');
  988. $list = UserWill::order(['isdefault' => 'desc', 'id' => 'asc'])->limit($limit)->page($page)->append(['isdefault_text'])->select();
  989. $count = UserWill::count();
  990. if ($count == 0) {
  991. exit(json_encode([
  992. 'code' => 1,
  993. 'msg' => "未查询到数据",
  994. ]));
  995. }
  996. exit(json_encode([
  997. 'code' => 0,
  998. 'msg' => "",
  999. 'count' => $count,
  1000. 'data' => $list,
  1001. ]));
  1002. }
  1003. public function editwill()
  1004. {
  1005. $id = input('id/d');
  1006. if (empty($id)) {
  1007. UserWill::create([
  1008. 'title' => input('title/s'),
  1009. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  1010. ]);
  1011. } else {
  1012. $administer = UserWill::find($id);
  1013. $administer->save([
  1014. 'title' => input('title/s'),
  1015. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  1016. ]);
  1017. }
  1018. exit(json_encode([
  1019. 'code' => 0,
  1020. ]));
  1021. }
  1022. public function delwill()
  1023. {
  1024. $access_admin = session('access_admin');
  1025. $password = input('password');
  1026. if ($access_admin['password'] !== md5($password)) {
  1027. exit(json_encode([
  1028. 'code' => 1,
  1029. 'msg' => "操作密码验证失败",
  1030. ]));
  1031. }
  1032. $idarr = input('idarr/a');
  1033. UserWill::whereIn('id', $idarr)->delete();
  1034. exit(json_encode([
  1035. 'code' => 0,
  1036. 'msg' => "",
  1037. ]));
  1038. }
  1039. public function importView()
  1040. {
  1041. return view('user/importview');
  1042. }
  1043. public function import()
  1044. {
  1045. $file_url = input('file_url/s', "");
  1046. if (!file_exists($file_url)) {
  1047. exit(json_encode([
  1048. 'code' => 1,
  1049. 'msg' => "文件不存在",
  1050. ]));
  1051. }
  1052. $service = new UserService();
  1053. $res = $service->importComjobs($file_url);
  1054. if (empty($res['code'])) {
  1055. exit(json_encode([
  1056. 'code' => 1,
  1057. 'msg' => $res['msg'],
  1058. ]));
  1059. }
  1060. exit(json_encode(['code' => 0]));
  1061. }
  1062. public function tags()
  1063. {
  1064. return view('user/tagslist');
  1065. }
  1066. public function listtags()
  1067. {
  1068. $limit = input('limit');
  1069. $page = input('page');
  1070. $map = [];
  1071. $keywords = input('keywords/s');
  1072. if (!empty($keywords)) {
  1073. $map[] = ['name', 'like', '%' . $keywords . '%'];
  1074. }
  1075. $list = UserTags::where($map)->limit($limit)->page($page)->select();
  1076. $count = UserTags::count();
  1077. if ($count == 0) {
  1078. exit(json_encode([
  1079. 'code' => 1,
  1080. 'msg' => "未查询到数据",
  1081. ]));
  1082. }
  1083. exit(json_encode([
  1084. 'code' => 0,
  1085. 'msg' => "",
  1086. 'count' => $count,
  1087. 'data' => $list,
  1088. ]));
  1089. }
  1090. public function deltags()
  1091. {
  1092. $idarr = input('idarr/a');
  1093. UserTags::whereIn('id', $idarr)->delete();
  1094. exit(json_encode([
  1095. 'code' => 0,
  1096. 'msg' => "",
  1097. ]));
  1098. }
  1099. public function tagsForm()
  1100. {
  1101. $id = input('id/d, 0');
  1102. $tags = UserTags::findOrEmpty($id);
  1103. return view('user/tagsform', [
  1104. 'tags' => $tags,
  1105. ]);
  1106. }
  1107. public function edittags()
  1108. {
  1109. $id = input('id/d');
  1110. if (empty($id)) {
  1111. UserTags::create([
  1112. 'name' => input('name/s'),
  1113. ]);
  1114. } else {
  1115. $administer = UserTags::find($id);
  1116. $administer->save([
  1117. 'name' => input('name/s'),
  1118. ]);
  1119. }
  1120. exit(json_encode([
  1121. 'code' => 0,
  1122. ]));
  1123. }
  1124. }