User.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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. if ($user->isempty()) {
  508. $user->broker_channel = 2;
  509. }
  510. $agentlist = AgentModel::with('broker')->order(['id' => 'asc'])->select();
  511. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  512. $willlist = UserWill::select();
  513. $usertags = UserTags::select();
  514. $emptimelist = RensheCode::getList('emp_time');
  515. $communitylist = RensheCode::getList('community')->toArray();
  516. array_push($communitylist, ['code' => 0, 'id' => 0, 'name' => "不限"]);
  517. $comlist = ComjobsCateModel::select();
  518. return view('user/userform', [
  519. 'groupslist' => $groupslist,
  520. 'willlist' => $willlist,
  521. 'usertags' => $usertags,
  522. 'agentlist' => $agentlist,
  523. 'user' => $user,
  524. 'emptimelist' => $emptimelist,
  525. 'communitylist' => $communitylist,
  526. 'comlist' => $comlist,
  527. ]);
  528. }
  529. public function fieldUser()
  530. {
  531. $id = input('id/d', 0);
  532. $user = UserModel::findOrEmpty($id);
  533. if ($user->isEmpty()) {
  534. exit(json_encode([
  535. 'code' => 1,
  536. 'msg' => "信息不存在",
  537. ]));
  538. } else {
  539. $user->save([
  540. input('field/s') => input('value'),
  541. ]);
  542. }
  543. exit(json_encode([
  544. 'code' => 0,
  545. ]));
  546. }
  547. public function listUser()
  548. {
  549. $limit = input('limit');
  550. $page = input('page');
  551. $map = [];
  552. $keywords = input('keywords/s');
  553. if (!empty($keywords)) {
  554. $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
  555. }
  556. $groupsid = input('groupsid/d');
  557. if (!empty($groupsid)) {
  558. $map[] = ['groupsid', '=', $groupsid];
  559. }
  560. $ispublic = input('ispublic/d', 0);
  561. if ($ispublic == 0) {
  562. $agentbrokerarr = explode(",", input('agentbroker/s'));
  563. $agentid = isset($agentbrokerarr[0]) ? $agentbrokerarr[0] : 0;
  564. if (!empty($agentid)) {
  565. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  566. $map[] = ['brokerid', 'in', $brokeridarr];
  567. $map[] = ['brokerid', '<>', 0];
  568. }
  569. $brokerid = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
  570. if (!empty($brokerid)) {
  571. $map[] = ['brokerid', '=', $brokerid];
  572. }
  573. } else {
  574. $map[] = ['brokerid', '=', 0];
  575. }
  576. $status = input('status/d');
  577. if (!empty($status)) {
  578. $map[] = ['status', '=', $status];
  579. }
  580. $authstatus = input('authstatus/d');
  581. if (!empty($authstatus)) {
  582. $map[] = ['authstatus', '=', $authstatus];
  583. }
  584. $followstatus = input('followstatus/d');
  585. if (!empty($followstatus)) {
  586. $map[] = ['followstatus', '=', $followstatus];
  587. }
  588. $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();
  589. $count = UserModel::where($map)->count();
  590. if ($count == 0) {
  591. exit(json_encode([
  592. 'code' => 1,
  593. 'msg' => "未查询到数据",
  594. ]));
  595. }
  596. exit(json_encode([
  597. 'code' => 0,
  598. 'msg' => "",
  599. 'count' => $count,
  600. 'data' => $list,
  601. ]));
  602. }
  603. public function exportUser()
  604. {
  605. $map = [];
  606. $keywords = input('keywords/s');
  607. if (!empty($keywords)) {
  608. $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
  609. }
  610. $groupsid = input('groupsid/d');
  611. if (!empty($groupsid)) {
  612. $map[] = ['groupsid', '=', $groupsid];
  613. }
  614. $agentbrokerarr = explode(",", input('agentbroker/s'));
  615. $agentid = isset($agentbrokerarr[0]) ? $agentbrokerarr[0] : 0;
  616. if (!empty($agentid)) {
  617. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  618. $map[] = ['brokerid', 'in', $brokeridarr];
  619. $map[] = ['brokerid', '<>', 0];
  620. }
  621. $brokerid = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
  622. if (!empty($brokerid)) {
  623. $map[] = ['brokerid', '=', $brokerid];
  624. }
  625. $status = input('status/d');
  626. if (!empty($status)) {
  627. $map[] = ['status', '=', $status];
  628. }
  629. $authstatus = input('authstatus/d');
  630. if (!empty($authstatus)) {
  631. $map[] = ['authstatus', '=', $authstatus];
  632. }
  633. $followstatus = input('followstatus/d');
  634. if (!empty($followstatus)) {
  635. $map[] = ['followstatus', '=', $followstatus];
  636. }
  637. $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();
  638. $xlsCell = [
  639. ['id', '表ID'],
  640. ['nickname', '昵称'],
  641. ['realname', '姓名'],
  642. ['mobile', '手机号'],
  643. ['integral', '可用积分'],
  644. ['inttotal', '累计积分'],
  645. ['status_text', '状态'],
  646. ['isvip_text', '是否VIP'],
  647. ['authstatus_text', '是否实名认证'],
  648. ['idcard', '身份证号'],
  649. ['gender', '性别', [1 => '男', 2 => '女']],
  650. ['birthday', '出生日期'],
  651. ['address', '现居住地'],
  652. ['education', '学历'],
  653. ['bankcard.openbank', '开户行'],
  654. ['bankcard.account', '账户名'],
  655. ['bankcard.number', '账户号'],
  656. ['followstatus_text', '跟进状态'],
  657. ['userGroups.title', '用户组'],
  658. ['broker.worker.title', '劳务公司'],
  659. ['broker.agent.title', '代理门店'],
  660. ['broker.title', '经纪人'],
  661. ['user_part_count', '推广人数'],
  662. ['createtime', '注册时间'],
  663. ];
  664. export_excel("系统用户", $xlsCell, $xlsData);
  665. }
  666. public function setBroker()
  667. {
  668. $idarr = input('idarr/a');
  669. $setagentbroker = explode(",", input('setagentbroker/s'));
  670. $brokerid = isset($setagentbroker[1]) ? $setagentbroker[1] : 0;
  671. if (empty($brokerid)) {
  672. exit(json_encode([
  673. 'code' => 1,
  674. 'msg' => "请选择经纪人。",
  675. ]));
  676. }
  677. UserModel::whereIn('id', $idarr)->update(['brokerid' => $brokerid, 'broker_channel' => 2]);
  678. exit(json_encode([
  679. 'code' => 0,
  680. 'msg' => "",
  681. ]));
  682. }
  683. public function delUser()
  684. {
  685. $idarr = input('idarr/a');
  686. UserModel::destroy($idarr);
  687. event('userDel', $idarr);
  688. exit(json_encode([
  689. 'code' => 0,
  690. 'msg' => "",
  691. ]));
  692. }
  693. public function editUser()
  694. {
  695. $id = input('id/d');
  696. $mobile = input('mobile/s');
  697. $vdata = [
  698. 'id' => $id,
  699. 'mobile' => $mobile,
  700. ];
  701. try {
  702. validate(UserValidate::class)->check($vdata);
  703. } catch (ValidateException $e) {
  704. exit(json_encode([
  705. 'code' => 1,
  706. 'msg' => $e->getError(),
  707. ]));
  708. }
  709. //手机号
  710. $check_user_where = [['mobile', '=', $mobile]];
  711. if (!empty($id)) {
  712. $check_user_where[] = ['id', '<>', $id];
  713. }
  714. $check_user = UserModel::where($check_user_where)->find();
  715. if (!empty($check_user)) {
  716. exit(json_encode([
  717. 'code' => 1,
  718. 'msg' => '手机号已存在',
  719. ]));
  720. }
  721. $address = input('address/s', "");
  722. $jobintention = input('jobintention/s', "");
  723. $agentbrokerarr = explode(",", input('agentbroker/s'));
  724. $brokerid = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
  725. $data = [
  726. 'groupsid' => input('groupsid/d', 0),
  727. 'brokerid' => $brokerid,
  728. 'nickname' => input('nickname/s', ""),
  729. 'avatar' => input('avatar/s', ""),
  730. 'realname' => input('realname/s', ""),
  731. 'mobile' => $mobile,
  732. 'inttotal' => input('inttotal/d', 0),
  733. 'status' => input('status/d', 1),
  734. 'isvip' => input('isvip/d', 1),
  735. 'authstatus' => input('authstatus/d', 1),
  736. 'authremark' => input('authremark/s', ""),
  737. 'idcardzpic' => input('idcardzpic/s', ""),
  738. 'idcardfpic' => input('idcardfpic/s', ""),
  739. 'idcard' => input('idcard/s', ""),
  740. 'gender' => input('gender/d', 1),
  741. 'birthday' => input('birthday/s', ""),
  742. 'address' => $address,
  743. 'education' => input('education/s', ""),
  744. 'createtime' => input('createtime/s', ""),
  745. 'jobintention' => $jobintention,
  746. 'workexperience' => input('workexperience/s', ""),
  747. 'eduexperience' => input('eduexperience/s', ""),
  748. 'followstatus' => input('followstatus/d', 1),
  749. 'bankcard' => input('bankcard/a', []),
  750. 'emp_time' => array_values(input('emp_time/a', [])),
  751. 'user_tags' => array_values(input('user_tags/a', [])),
  752. 'work_place' => array_values(input('work_place/a', [])),
  753. 'com_cate_type' => input('com_cate_type/d', 1),
  754. 'com_cate' => array_values(input('com_cate/a', [])),
  755. 'com_cate_other' => input('com_cate_other/s', ""),
  756. 'skill_cert' => array_values(input('skill_cert/a', [])),
  757. ];
  758. $password = input('password/s');
  759. if (empty($id)) {
  760. $data['integral'] = 0;
  761. $data['wxampcode'] = '';
  762. $data['broker_channel'] = 2;
  763. $user = UserModel::create($data);
  764. UserAuthsModel::create([
  765. 'userid' => $user->id,
  766. 'identitytype' => "mobile",
  767. 'identifier' => $mobile,
  768. 'password' => empty($password) ? md5("123456789") : md5($password),
  769. 'logintime' => time(),
  770. 'loginip' => $_SERVER['SERVER_ADDR'],
  771. 'wxampcode' => "",
  772. ]);
  773. } else {
  774. $data['id'] = $id;
  775. $user = UserModel::find($id);
  776. if ($user['brokerid'] != $brokerid) {
  777. $data['broker_channel'] = 2;
  778. }
  779. UserModel::update($data);
  780. $adata = ['identifier' => $mobile];
  781. if (!empty($password)) {
  782. $adata['password'] = md5($password);
  783. }
  784. UserAuthsModel::update($adata, ['userid' => $id, 'identitytype' => 'mobile']);
  785. //实名认证积分
  786. $user = UserModel::where('id', $id)->find();
  787. if ($user['authstatus'] == 3 && $user['is_auth'] == 2) {
  788. $user->is_auth = 1;
  789. $user->save();
  790. /*$integralService = new IntegralService();
  791. $integralService->add($id, IntegralService::CERTIFICATION);*/
  792. //发放佣金
  793. $balanceService = new BalanceService();
  794. $balanceService->add($id, BalanceService::CERTIFICATION);
  795. }
  796. }
  797. exit(json_encode([
  798. 'code' => 0,
  799. ]));
  800. }
  801. // 用户组
  802. public function groupsList()
  803. {
  804. return view('user/groupslist');
  805. }
  806. public function groupsForm()
  807. {
  808. $id = input('id/d, 0');
  809. $groups = UserGroupsModel::findOrEmpty($id);
  810. return view('user/groupsform', [
  811. 'groups' => $groups,
  812. ]);
  813. }
  814. public function listGroups()
  815. {
  816. $limit = input('limit');
  817. $page = input('page');
  818. $list = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->limit($limit)->page($page)->append(['isdefault_text'])->select();
  819. $count = UserGroupsModel::count();
  820. if ($count == 0) {
  821. exit(json_encode([
  822. 'code' => 1,
  823. 'msg' => "未查询到数据",
  824. ]));
  825. }
  826. exit(json_encode([
  827. 'code' => 0,
  828. 'msg' => "",
  829. 'count' => $count,
  830. 'data' => $list,
  831. ]));
  832. }
  833. public function editGroups()
  834. {
  835. $id = input('id/d');
  836. if (empty($id)) {
  837. $groups = UserGroupsModel::create([
  838. 'title' => input('title/s'),
  839. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  840. ]);
  841. } else {
  842. $administer = UserGroupsModel::find($id);
  843. $administer->save([
  844. 'title' => input('title/s'),
  845. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  846. ]);
  847. }
  848. exit(json_encode([
  849. 'code' => 0,
  850. ]));
  851. }
  852. public function delGroups()
  853. {
  854. $access_admin = session('access_admin');
  855. $password = input('password');
  856. if ($access_admin['password'] !== md5($password)) {
  857. exit(json_encode([
  858. 'code' => 1,
  859. 'msg' => "操作密码验证失败",
  860. ]));
  861. }
  862. $idarr = input('idarr/a');
  863. UserGroupsModel::whereIn('id', $idarr)->delete();
  864. exit(json_encode([
  865. 'code' => 0,
  866. 'msg' => "",
  867. ]));
  868. }
  869. // 参数设置
  870. public function param()
  871. {
  872. $param = UserParamModel::where(1)->findOrEmpty();
  873. return view('user/param', [
  874. 'param' => $param,
  875. ]);
  876. }
  877. public function editParam()
  878. {
  879. $param = UserParamModel::where(1)->findOrEmpty();
  880. $data = [
  881. 'redmoney' => input('redmoney/d', 0),
  882. 'usernumber' => input('usernumber/d', 0),
  883. 'shareintegral' => input('shareintegral/d', 0),
  884. 'postintegral' => input('postintegral/d', 0),
  885. 'inttomoney' => input('inttomoney/d', 0),
  886. 'minintegral' => input('minintegral/d', 0),
  887. 'intrecharge' => input('intrecharge/d', 0),
  888. 'picregworker' => input('picregworker/s', ""),
  889. 'intregworker' => input('intregworker/d', 0),
  890. 'register' => input('register/d', 0),
  891. 'improveresume' => input('improveresume/d', 0),
  892. 'certification' => input('certification/d', 0),
  893. 'entry' => input('entry/d', 0),
  894. 'signin' => input('signin/d', 0),
  895. 'sharejob' => input('sharejob/d', 0),
  896. 'sharejobnum' => input('sharejobnum/d', 0),
  897. 'taskimage' => input('taskimage/s', ''),
  898. ];
  899. if ($param->isEmpty()) {
  900. UserParamModel::create($data);
  901. } else {
  902. $data['id'] = $param->id;
  903. UserParamModel::update($data);
  904. }
  905. exit(json_encode([
  906. 'code' => 0,
  907. 'msg' => "",
  908. ]));
  909. }
  910. // 提现设置
  911. public function getmoney()
  912. {
  913. $param = UserParamModel::where(1)->findOrEmpty();
  914. return view('user/getmoney', [
  915. 'getmoney' => $param['getmoney'],
  916. ]);
  917. }
  918. public function editGetmoney()
  919. {
  920. $param = UserParamModel::where(1)->findOrEmpty();
  921. $data = [
  922. 'getmoney' => input('getmoney/a', []),
  923. ];
  924. foreach ($data['getmoney'] as $v) {
  925. if ($v['money'] < 0.3) {
  926. exit(json_encode([
  927. 'code' => 1,
  928. 'msg' => "金额必须大于等于0.3",
  929. ]));
  930. }
  931. if ($v['num'] <= 0) {
  932. exit(json_encode([
  933. 'code' => 1,
  934. 'msg' => "次数必须大于等于0",
  935. ]));
  936. }
  937. }
  938. if ($param->isEmpty()) {
  939. UserParamModel::create($data);
  940. } else {
  941. $param->getmoney = $data['getmoney'];
  942. $param->save();
  943. }
  944. exit(json_encode([
  945. 'code' => 0,
  946. 'msg' => "",
  947. ]));
  948. }
  949. // 佣金设置
  950. public function commission()
  951. {
  952. $param = UserParamModel::where(1)->findOrEmpty();
  953. return view('user/commission', [
  954. 'commission' => $param['commission'],
  955. ]);
  956. }
  957. public function editCommission()
  958. {
  959. $param = UserParamModel::where(1)->findOrEmpty();
  960. $data = [
  961. 'commission' => input('commission/a', []),
  962. ];
  963. if ($param->isEmpty()) {
  964. UserParamModel::create($data);
  965. } else {
  966. $param->commission = $data['commission'];
  967. $param->save();
  968. }
  969. exit(json_encode([
  970. 'code' => 0,
  971. 'msg' => "",
  972. ]));
  973. }
  974. // 用户组
  975. public function willList()
  976. {
  977. return view('user/willlist');
  978. }
  979. public function willForm()
  980. {
  981. $id = input('id/d, 0');
  982. $will = UserWill::findOrEmpty($id);
  983. return view('user/willform', [
  984. 'will' => $will,
  985. ]);
  986. }
  987. public function listwill()
  988. {
  989. $limit = input('limit');
  990. $page = input('page');
  991. $list = UserWill::order(['isdefault' => 'desc', 'id' => 'asc'])->limit($limit)->page($page)->append(['isdefault_text'])->select();
  992. $count = UserWill::count();
  993. if ($count == 0) {
  994. exit(json_encode([
  995. 'code' => 1,
  996. 'msg' => "未查询到数据",
  997. ]));
  998. }
  999. exit(json_encode([
  1000. 'code' => 0,
  1001. 'msg' => "",
  1002. 'count' => $count,
  1003. 'data' => $list,
  1004. ]));
  1005. }
  1006. public function editwill()
  1007. {
  1008. $id = input('id/d');
  1009. if (empty($id)) {
  1010. UserWill::create([
  1011. 'title' => input('title/s'),
  1012. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  1013. ]);
  1014. } else {
  1015. $administer = UserWill::find($id);
  1016. $administer->save([
  1017. 'title' => input('title/s'),
  1018. 'isdefault' => input('isdefault/d') == 2 ? 2 : 1,
  1019. ]);
  1020. }
  1021. exit(json_encode([
  1022. 'code' => 0,
  1023. ]));
  1024. }
  1025. public function delwill()
  1026. {
  1027. $access_admin = session('access_admin');
  1028. $password = input('password');
  1029. if ($access_admin['password'] !== md5($password)) {
  1030. exit(json_encode([
  1031. 'code' => 1,
  1032. 'msg' => "操作密码验证失败",
  1033. ]));
  1034. }
  1035. $idarr = input('idarr/a');
  1036. UserWill::whereIn('id', $idarr)->delete();
  1037. exit(json_encode([
  1038. 'code' => 0,
  1039. 'msg' => "",
  1040. ]));
  1041. }
  1042. public function importView()
  1043. {
  1044. return view('user/importview');
  1045. }
  1046. public function import()
  1047. {
  1048. $file_url = input('file_url/s', "");
  1049. if (!file_exists($file_url)) {
  1050. exit(json_encode([
  1051. 'code' => 1,
  1052. 'msg' => "文件不存在",
  1053. ]));
  1054. }
  1055. $service = new UserService();
  1056. $res = $service->importComjobs($file_url);
  1057. if (empty($res['code'])) {
  1058. exit(json_encode([
  1059. 'code' => 1,
  1060. 'msg' => $res['msg'],
  1061. ]));
  1062. }
  1063. exit(json_encode(['code' => 0]));
  1064. }
  1065. public function tags()
  1066. {
  1067. return view('user/tagslist');
  1068. }
  1069. public function listtags()
  1070. {
  1071. $limit = input('limit');
  1072. $page = input('page');
  1073. $map = [];
  1074. $keywords = input('keywords/s');
  1075. if (!empty($keywords)) {
  1076. $map[] = ['name', 'like', '%' . $keywords . '%'];
  1077. }
  1078. $list = UserTags::where($map)->limit($limit)->page($page)->select();
  1079. $count = UserTags::count();
  1080. if ($count == 0) {
  1081. exit(json_encode([
  1082. 'code' => 1,
  1083. 'msg' => "未查询到数据",
  1084. ]));
  1085. }
  1086. exit(json_encode([
  1087. 'code' => 0,
  1088. 'msg' => "",
  1089. 'count' => $count,
  1090. 'data' => $list,
  1091. ]));
  1092. }
  1093. public function deltags()
  1094. {
  1095. $idarr = input('idarr/a');
  1096. UserTags::whereIn('id', $idarr)->delete();
  1097. exit(json_encode([
  1098. 'code' => 0,
  1099. 'msg' => "",
  1100. ]));
  1101. }
  1102. public function tagsForm()
  1103. {
  1104. $id = input('id/d, 0');
  1105. $tags = UserTags::findOrEmpty($id);
  1106. return view('user/tagsform', [
  1107. 'tags' => $tags,
  1108. ]);
  1109. }
  1110. public function edittags()
  1111. {
  1112. $id = input('id/d');
  1113. if (empty($id)) {
  1114. UserTags::create([
  1115. 'name' => input('name/s'),
  1116. ]);
  1117. } else {
  1118. $administer = UserTags::find($id);
  1119. $administer->save([
  1120. 'name' => input('name/s'),
  1121. ]);
  1122. }
  1123. exit(json_encode([
  1124. 'code' => 0,
  1125. ]));
  1126. }
  1127. }