Agent.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use app\common\model\User as UserModel;
  5. use app\common\model\Worker as WorkerModel;
  6. use app\common\model\Agent as AgentModel;
  7. use app\common\model\AgentForm as AgentFormModel;
  8. use app\common\model\Broker as BrokerModel;
  9. use app\common\validate\Agent as AgentValidate;
  10. use think\exception\ValidateException;
  11. use think\facade\Db;
  12. class Agent extends BaseController
  13. {
  14. public function agentList()
  15. {
  16. $workerlist = WorkerModel::order(['id' => 'desc'])->select();
  17. return view('agent/agentlist', [
  18. 'workerlist' => $workerlist,
  19. ]);
  20. }
  21. public function agentForm()
  22. {
  23. $id = input('id/d, 0');
  24. $agent = AgentModel::with(['muser'])->findOrEmpty($id);
  25. $workerlist = WorkerModel::order(['id' => 'desc'])->select();
  26. return view('agent/agentform', [
  27. 'workerlist' => $workerlist,
  28. 'agent' => $agent,
  29. ]);
  30. }
  31. public function editAgent()
  32. {
  33. $id = input('id/d');
  34. $vdata = [
  35. 'id' => $id,
  36. 'loginname' => input('loginname/s', ""),
  37. 'idnumber' => input('idnumber/s', ""),
  38. ];
  39. try {
  40. validate(AgentValidate::class)->check($vdata);
  41. } catch (ValidateException $e) {
  42. exit(json_encode([
  43. 'code' => 1,
  44. 'msg' => $e->getError(),
  45. ]));
  46. }
  47. $muser = UserModel::where(['mobile' => input('musermobile/s', '')])->findOrEmpty();
  48. if ($muser->isEmpty()) {
  49. exit(json_encode([
  50. 'code' => 1,
  51. 'msg' => "关联的用户不存在。",
  52. ]));
  53. }
  54. $data = [
  55. 'userid' => $muser->id,
  56. 'workerid' => input('workerid/d', 0),
  57. 'loginname' => input('loginname/s', ""),
  58. 'idnumber' => input('idnumber/s', ""),
  59. 'title' => input('title/s', ""),
  60. 'tilpic' => input('tilpic/s', ""),
  61. 'picall' => input('picall/a', []),
  62. 'realname' => input('realname/s', ""),
  63. 'mobile' => input('mobile/s', ""),
  64. 'telephone' => input('telephone/s', ""),
  65. 'latitude' => input('latitude/f', 0.00),
  66. 'longitude' => input('longitude/f', 0.00),
  67. 'province' => input('province/s', ""),
  68. 'city' => input('city/s', ""),
  69. 'district' => input('district/s', ""),
  70. 'address' => input('address/s', ""),
  71. 'details' => input('details/s', ""),
  72. 'priority' => input('priority/d', 0),
  73. 'remark' => input('remark/s', ""),
  74. 'status' => input('status/d', 1),
  75. 'is_settle' => input('is_settle/d', 1),
  76. ];
  77. $password = input('password/s', "");
  78. if (empty($id)) {
  79. $data['password'] = empty($password) ? md5("123456789") : md5($password);
  80. $data['createtime'] = time();
  81. $agent = AgentModel::create($data);
  82. } else {
  83. if (!empty($password)) {
  84. $data['password'] = md5($password);
  85. }
  86. $agent = AgentModel::find($id);
  87. $agent->save($data);
  88. }
  89. BrokerModel::update([
  90. 'workerid' => input('workerid/d', 0),
  91. ], ['agentid' => $agent->id]);
  92. exit(json_encode([
  93. 'code' => 0,
  94. ]));
  95. }
  96. public function fieldAgent()
  97. {
  98. $id = input('id/d', 0);
  99. $info = AgentModel::findOrEmpty($id);
  100. if ($info->isEmpty()) {
  101. exit(json_encode([
  102. 'code' => 1,
  103. 'msg' => "信息不存在",
  104. ]));
  105. } else {
  106. $info->save([
  107. input('field/s') => input('value/s', ""),
  108. ]);
  109. }
  110. exit(json_encode([
  111. 'code' => 0,
  112. ]));
  113. }
  114. public function delAgent()
  115. {
  116. $access_admin = session('access_admin');
  117. $password = input('password');
  118. if ($access_admin['password'] !== md5($password)) {
  119. exit(json_encode([
  120. 'code' => 1,
  121. 'msg' => "操作密码验证失败",
  122. ]));
  123. }
  124. $idarr = input('idarr/a');
  125. $result = Db::name('agent')->whereIn('id', $idarr)->update(['deletetime' => time()]);
  126. if ($result) {
  127. exit(json_encode([
  128. 'code' => 0,
  129. 'msg' => "",
  130. ]));
  131. }
  132. exit(json_encode([
  133. 'code' => 1,
  134. 'msg' => "删除失败,请稍后重试",
  135. ]));
  136. }
  137. public function listAgent()
  138. {
  139. $limit = input('limit');
  140. $page = input('page');
  141. $map = [];
  142. $keywords = input('keywords/s');
  143. if (!empty($keywords)) {
  144. $map[] = ['idnumber', 'like', '%' . $keywords . '%'];
  145. }
  146. $workerid = input('workerid/d');
  147. if (!empty($workerid)) {
  148. $map[] = ['workerid', '=', $workerid];
  149. }
  150. $status = input('status/d');
  151. if (!empty($status)) {
  152. $map[] = ['status', '=', $status];
  153. }
  154. $list = AgentModel::with(['worker', 'muser'])->where($map)->order(['priority' => 'DESC', 'id' => 'DESC'])->limit($limit)->page($page)->append(['status_text'])->select();
  155. $count = AgentModel::where($map)->count();
  156. if ($count == 0) {
  157. exit(json_encode([
  158. 'code' => 1,
  159. 'msg' => "未查询到数据",
  160. ]));
  161. }
  162. exit(json_encode([
  163. 'code' => 0,
  164. 'msg' => "",
  165. 'count' => $count,
  166. 'data' => $list,
  167. ]));
  168. }
  169. // 申请注册经纪人
  170. public function fagentList()
  171. {
  172. return view('agent/fagentlist');
  173. }
  174. public function fagentForm()
  175. {
  176. $id = input('id/d, 0');
  177. $fagent = AgentFormModel::findOrEmpty($id);
  178. return view('agent/fagentform', [
  179. 'fagent' => $fagent,
  180. ]);
  181. }
  182. public function editFagent()
  183. {
  184. $id = input('id/d');
  185. $fagent = AgentFormModel::findOrEmpty($id);
  186. $fagent->save([
  187. 'realname' => input('realname/s', ""),
  188. 'mobile' => input('mobile/s', ""),
  189. 'address' => input('address/s', ""),
  190. 'idcard' => input('idcard/s', ""),
  191. 'recommender' => input('recommender/s', ""),
  192. 'status' => input('status/d', 1),
  193. 'remark' => input('remark/s', ""),
  194. 'createtime' => input('createtime/s', ""),
  195. ]);
  196. exit(json_encode([
  197. 'code' => 0,
  198. ]));
  199. }
  200. public function fieldFagent()
  201. {
  202. $id = input('id/d', 0);
  203. $info = AgentFormModel::findOrEmpty($id);
  204. if ($info->isEmpty()) {
  205. exit(json_encode([
  206. 'code' => 1,
  207. 'msg' => "信息不存在",
  208. ]));
  209. } else {
  210. $info->save([
  211. input('field/s') => input('value'),
  212. ]);
  213. }
  214. exit(json_encode([
  215. 'code' => 0,
  216. ]));
  217. }
  218. public function delFagent()
  219. {
  220. $idarr = input('idarr/a');
  221. $fagent = AgentFormModel::whereIn('id', $idarr)->select();
  222. $result = $fagent->delete();
  223. if ($result) {
  224. exit(json_encode([
  225. 'code' => 0,
  226. 'msg' => "",
  227. ]));
  228. }
  229. exit(json_encode([
  230. 'code' => 1,
  231. 'msg' => "删除失败,请稍后重试",
  232. ]));
  233. }
  234. public function listFagent()
  235. {
  236. $limit = input('limit');
  237. $page = input('page');
  238. $map = [];
  239. $keywords = input('keywords/s');
  240. if (!empty($keywords)) {
  241. $map[] = ['realname|mobile', 'like', '%' . $keywords . '%'];
  242. }
  243. $status = input('status/d');
  244. if (!empty($status)) {
  245. $map[] = ['status', '=', $status];
  246. }
  247. $list = AgentFormModel::where($map)->order('id', 'DESC')->limit($limit)->page($page)->append(['status_text'])->select();
  248. $count = AgentFormModel::where($map)->count();
  249. if ($count == 0) {
  250. exit(json_encode([
  251. 'code' => 1,
  252. 'msg' => "未查询到数据",
  253. ]));
  254. }
  255. exit(json_encode([
  256. 'code' => 0,
  257. 'msg' => "",
  258. 'count' => $count,
  259. 'data' => $list,
  260. ]));
  261. }
  262. }