User.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <?php
  2. namespace app\agent\controller;
  3. use app\common\model\ComjobsCate;
  4. use app\common\model\RensheCode;
  5. use app\common\model\UserWill;
  6. use think\facade\Session;
  7. use app\agent\BaseController;
  8. use app\common\model\User as UserModel;
  9. use app\common\model\UserAuths as UserAuthsModel;
  10. use app\common\model\UserFollow as UserFollowModel;
  11. use app\common\model\UserGroups as UserGroupsModel;
  12. use app\common\model\Broker as BrokerModel;
  13. use app\common\validate\User as UserValidate;
  14. use think\exception\ValidateException;
  15. use PHPExcel_IOFactory;
  16. use PHPExcel;
  17. class User extends BaseController
  18. {
  19. // 用户跟进记录
  20. public function follow()
  21. {
  22. $userid = input('userid/d');
  23. $user = UserModel::findOrEmpty($userid);
  24. $followlist = UserFollowModel::where('userid', $userid)->order('id', 'desc')->limit(100)->select();
  25. return view('user/follow', [
  26. 'user' => $user,
  27. 'followlist' => $followlist,
  28. ]);
  29. }
  30. public function editFollow()
  31. {
  32. $userid = input('userid/d', 0);
  33. $user = UserModel::findOrEmpty($userid);
  34. if ($user->isEmpty()) {
  35. exit(json_encode([
  36. 'code' => 1,
  37. 'msg' => "用户信息不存在。",
  38. ]));
  39. }
  40. $agent = $this->access_agent;
  41. $broker = BrokerModel::where('agentid', '=', $agent['id'])->findOrEmpty($user->brokerid);
  42. if ($broker->isEmpty()) {
  43. exit(json_encode([
  44. 'code' => 1,
  45. 'msg' => "你无权限上报该用户跟进记录。",
  46. ]));
  47. }
  48. UserFollowModel::create([
  49. 'userid' => $userid,
  50. 'ftype' => input('ftype/s', ""),
  51. 'remark' => input('remark/s', ""),
  52. 'createtime' => time(),
  53. ]);
  54. $followstatus = input('followstatus/d', 1);
  55. $user->save([
  56. 'followstatus' => $followstatus,
  57. ]);
  58. exit(json_encode([
  59. 'code' => 0,
  60. ]));
  61. }
  62. // 用户授权
  63. public function authsList()
  64. {
  65. $userid = input('userid/d');
  66. return view('user/authslist', [
  67. 'userid' => $userid,
  68. ]);
  69. }
  70. public function listAuths()
  71. {
  72. $userid = input('userid/d');
  73. $list = UserAuthsModel::where('userid', $userid)->order('id', 'asc')->append(['identitytype_text'])->select();
  74. $count = UserAuthsModel::where('userid', $userid)->count();
  75. if ($count == 0) {
  76. exit(json_encode([
  77. 'code' => 1,
  78. 'msg' => "未查询到数据",
  79. ]));
  80. }
  81. exit(json_encode([
  82. 'code' => 0,
  83. 'msg' => "",
  84. 'count' => $count,
  85. 'data' => $list,
  86. ]));
  87. }
  88. public function delAuths()
  89. {
  90. $id = input('id/d');
  91. $auths = UserAuthsModel::find($id);
  92. if ($auths->identitytype == 'mobile') {
  93. exit(json_encode([
  94. 'code' => 1,
  95. 'msg' => "手机号授权方式不允许删除",
  96. ]));
  97. }
  98. $result = $auths->delete();
  99. if ($result) {
  100. exit(json_encode([
  101. 'code' => 0,
  102. ]));
  103. }
  104. exit(json_encode([
  105. 'code' => 1,
  106. 'msg' => "删除失败,请稍后重试",
  107. ]));
  108. }
  109. // 用户
  110. public function userList()
  111. {
  112. $agentid = $this->access_agent['id'];
  113. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  114. $brokerlist = BrokerModel::where('agentid', '=', $agentid)->order(['id' => 'desc'])->select();
  115. return view('user/userlist', [
  116. 'groupslist' => $groupslist,
  117. 'brokerlist' => $brokerlist,
  118. ]);
  119. }
  120. public function userForm()
  121. {
  122. $agentid = $this->access_agent['id'];
  123. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  124. $id = input('id/d', 0);
  125. $user = UserModel::whereIn('brokerid', $brokeridarr)->where('brokerid', '<>', 0)->findOrEmpty($id);
  126. $agent = $this->access_agent;
  127. $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
  128. $brokerlist = BrokerModel::where('agentid', '=', $agentid)->order(['id' => 'desc'])->select();
  129. $willlist = UserWill::select();
  130. $emptimelist = RensheCode::getList('emp_time');
  131. $communitylist = RensheCode::getList('community')->toArray();
  132. array_push($communitylist, ['code' => 0, 'id' => 0, 'name' => "不限"]);
  133. $comlist = ComjobsCate::select();
  134. return view('user/userform', [
  135. 'brokerlist' => $brokerlist,
  136. 'groupslist' => $groupslist,
  137. 'agent' => $agent,
  138. 'user' => $user,
  139. 'willlist' => $willlist,
  140. 'emptimelist' => $emptimelist,
  141. 'communitylist' => $communitylist,
  142. 'comlist' => $comlist,
  143. ]);
  144. }
  145. public function fieldUser()
  146. {
  147. $agentid = $this->access_agent['id'];
  148. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  149. $id = input('id/d', 0);
  150. $user = UserModel::whereIn('brokerid', $brokeridarr)->where('brokerid', '<>', 0)->findOrEmpty($id);
  151. if ($user->isEmpty()) {
  152. exit(json_encode([
  153. 'code' => 1,
  154. 'msg' => "信息不存在",
  155. ]));
  156. } else {
  157. $user->save([
  158. input('field/s') => input('value/s'),
  159. ]);
  160. }
  161. exit(json_encode([
  162. 'code' => 0,
  163. ]));
  164. }
  165. public function listUser()
  166. {
  167. $agentid = $this->access_agent['id'];
  168. $limit = input('limit', 20);
  169. $page = input('page', 1);
  170. $map = [];
  171. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  172. if (!empty($brokeridarr)) {
  173. $map[] = ['brokerid', 'in', $brokeridarr];
  174. } else {
  175. $map[] = ['brokerid', '=', -1];
  176. }
  177. $keywords = input('keywords/s');
  178. if (!empty($keywords)) {
  179. $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
  180. }
  181. $groupsid = input('groupsid/d');
  182. if (!empty($groupsid)) {
  183. $map[] = ['groupsid', '=', $groupsid];
  184. }
  185. $brokerid = input('brokerid/d');
  186. if (!empty($brokerid)) {
  187. $map[] = ['brokerid', '=', $brokerid];
  188. }
  189. $status = input('status/d');
  190. if (!empty($status)) {
  191. $map[] = ['status', '=', $status];
  192. }
  193. $authstatus = input('authstatus/d');
  194. if (!empty($authstatus)) {
  195. $map[] = ['authstatus', '=', $authstatus];
  196. }
  197. $followstatus = input('followstatus/d');
  198. if (!empty($followstatus)) {
  199. $map[] = ['followstatus', '=', $followstatus];
  200. }
  201. $list = UserModel::with(['userGroups', 'broker'])->where($map)->order('id', 'desc')->limit($limit)->page($page)->append(['status_text', 'isvip_text', 'authstatus_text', 'followstatus_text'])->select();
  202. $count = UserModel::where($map)->count();
  203. if ($count == 0) {
  204. exit(json_encode([
  205. 'code' => 1,
  206. 'msg' => "未查询到数据",
  207. ]));
  208. }
  209. exit(json_encode([
  210. 'code' => 0,
  211. 'msg' => "",
  212. 'count' => $count,
  213. 'data' => $list,
  214. ]));
  215. }
  216. public function exportUser()
  217. {
  218. $agentid = $this->access_agent['id'];
  219. $map = [];
  220. $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
  221. $map[] = ['brokerid', 'in', $brokeridarr];
  222. $map[] = ['brokerid', '<>', 0];
  223. $keywords = input('keywords/s');
  224. if (!empty($keywords)) {
  225. $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
  226. }
  227. $groupsid = input('groupsid/d');
  228. if (!empty($groupsid)) {
  229. $map[] = ['groupsid', '=', $groupsid];
  230. }
  231. $brokerid = input('brokerid/d');
  232. if (!empty($brokerid)) {
  233. $map[] = ['brokerid', '=', $brokerid];
  234. }
  235. $status = input('status/d');
  236. if (!empty($status)) {
  237. $map[] = ['status', '=', $status];
  238. }
  239. $authstatus = input('authstatus/d');
  240. if (!empty($authstatus)) {
  241. $map[] = ['authstatus', '=', $authstatus];
  242. }
  243. $followstatus = input('followstatus/d');
  244. if (!empty($followstatus)) {
  245. $map[] = ['followstatus', '=', $followstatus];
  246. }
  247. $xlsData = UserModel::with(['userGroups', 'broker'])->where($map)->order('id', 'desc')->append(['status_text', 'isvip_text', 'authstatus_text', 'followstatus_text'])->select()->toArray();
  248. $xlsCell = [
  249. ['id', '表ID'],
  250. ['nickname', '昵称'],
  251. ['realname', '姓名'],
  252. ['mobile', '手机号'],
  253. ['status_text', '状态'],
  254. ['isvip_text', '是否VIP'],
  255. ['authstatus_text', '是否实名认证'],
  256. ['idcard', '身份证号'],
  257. ['gender', '性别', [1 => '男', 2 => '女']],
  258. ['birthday', '出生日期'],
  259. ['address', '现居住地'],
  260. ['education', '学历'],
  261. ['bankcard.openbank', '开户行'],
  262. ['bankcard.account', '账户名'],
  263. ['bankcard.number', '账户号'],
  264. ['followstatus_text', '跟进状态'],
  265. ['userGroups.title', '用户组'],
  266. ['broker.title', '职业顾问'],
  267. ['createtime', '注册时间'],
  268. ];
  269. export_excel("系统用户", $xlsCell, $xlsData);
  270. }
  271. public function editUser()
  272. {
  273. $id = input('id/d');
  274. $mobile = input('mobile/s');
  275. $vdata = [
  276. 'id' => $id,
  277. 'mobile' => $mobile,
  278. ];
  279. try {
  280. validate(UserValidate::class)->check($vdata);
  281. } catch (ValidateException $e) {
  282. exit(json_encode([
  283. 'code' => 1,
  284. 'msg' => $e->getError(),
  285. ]));
  286. }
  287. $data = [
  288. 'groupsid' => input('groupsid/d', 0),
  289. 'brokerid' => input('brokerid/d', 0),
  290. 'nickname' => input('nickname/s', ""),
  291. 'avatar' => input('avatar/s', ""),
  292. 'realname' => input('realname/s', ""),
  293. 'mobile' => $mobile,
  294. 'status' => input('status/d', 1),
  295. 'isvip' => input('isvip/d', 1),
  296. 'authstatus' => input('authstatus/d', 1),
  297. 'authremark' => input('authremark/s', ""),
  298. 'idcardzpic' => input('idcardzpic/s', ""),
  299. 'idcardfpic' => input('idcardfpic/s', ""),
  300. 'idcard' => input('idcard/s', ""),
  301. 'gender' => input('gender/d', 1),
  302. 'birthday' => input('birthday/s', ""),
  303. 'address' => input('address/s', ""),
  304. 'education' => input('education/s', ""),
  305. 'jobintention' => input('jobintention/s', ""),
  306. 'workexperience' => input('workexperience/s', ""),
  307. 'eduexperience' => input('eduexperience/s', ""),
  308. 'followstatus' => input('followstatus/d', 1),
  309. 'bankcard' => input('bankcard/a', []),
  310. ];
  311. $password = input('password/s');
  312. if (empty($id)) {
  313. $data['integral'] = 0;
  314. $data['inttotal'] = 0;
  315. $data['createtime'] = time();
  316. $user = UserModel::create($data);
  317. $auths = UserAuthsModel::create([
  318. 'userid' => $user->id,
  319. 'identitytype' => "mobile",
  320. 'identifier' => $mobile,
  321. 'password' => empty($password) ? md5("123456789") : md5($password),
  322. 'logintime' => time(),
  323. 'loginip' => $_SERVER['SERVER_ADDR'],
  324. 'wxampcode' => "",
  325. ]);
  326. } else {
  327. $data['id'] = $id;
  328. $user = UserModel::update($data);
  329. $adata = ['identifier' => $mobile];
  330. if (!empty($password)) {
  331. $adata['password'] = md5($password);
  332. }
  333. UserAuthsModel::update($adata, ['userid' => $id, 'identitytype' => 'mobile']);
  334. }
  335. exit(json_encode([
  336. 'code' => 0,
  337. ]));
  338. }
  339. }