User.php 35 KB

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