User.php 37 KB

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