User.php 37 KB

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