Agent.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 = array(
  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(array(
  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(array(
  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', array()),
  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', 0)
  75. ];
  76. $password = input('password/s', "");
  77. if (empty($id)){
  78. $data['password'] = empty($password) ? md5("123456789") : md5($password);
  79. $data['createtime'] = time();
  80. $agent = AgentModel::create($data);
  81. }else{
  82. if (!empty($password)){
  83. $data['password'] = md5($password);
  84. }
  85. $agent = AgentModel::find($id);
  86. $agent->save($data);
  87. }
  88. BrokerModel::update([
  89. 'workerid' => input('workerid/d', 0)
  90. ],['agentid'=>$agent->id]);
  91. exit(json_encode(array(
  92. 'code' => 0
  93. )));
  94. }
  95. public function fieldAgent()
  96. {
  97. $id = input('id/d',0);
  98. $info = AgentModel::findOrEmpty($id);
  99. if ($info->isEmpty()){
  100. exit(json_encode(array(
  101. 'code' => 1,
  102. 'msg' => "信息不存在"
  103. )));
  104. }else{
  105. $info->save([
  106. input('field/s') => input('value/s', "")
  107. ]);
  108. }
  109. exit(json_encode(array(
  110. 'code' => 0
  111. )));
  112. }
  113. public function delAgent()
  114. {
  115. $access_admin = session('access_admin');
  116. $password = input('password');
  117. if ( $access_admin['password'] !== md5($password) ){
  118. exit(json_encode(array(
  119. 'code' => 1,
  120. 'msg' => "操作密码验证失败"
  121. )));
  122. }
  123. $idarr = input('idarr/a');
  124. $result = Db::name('agent')->whereIn('id',$idarr)->update(['deletetime'=>time()]);
  125. if ($result){
  126. exit(json_encode(array(
  127. 'code' => 0,
  128. 'msg' => ""
  129. )));
  130. }
  131. exit(json_encode(array(
  132. 'code' => 1,
  133. 'msg' => "删除失败,请稍后重试"
  134. )));
  135. }
  136. public function listAgent()
  137. {
  138. $limit = input('limit');
  139. $page = input('page');
  140. $map = array();
  141. $keywords = input('keywords/s');
  142. if (!empty($keywords)){
  143. $map[] =['idnumber', 'like', '%'.$keywords.'%'];
  144. }
  145. $workerid = input('workerid/d');
  146. if (!empty($workerid)){
  147. $map[] = ['workerid', '=', $workerid];
  148. }
  149. $status = input('status/d');
  150. if (!empty($status)){
  151. $map[] = ['status', '=', $status];
  152. }
  153. $list = AgentModel::with(['worker','muser'])->where($map)->order(['priority'=>'DESC','id'=>'DESC'])->limit($limit)->page($page)->append(['status_text'])->select();
  154. $count = AgentModel::where($map)->count();
  155. if ($count==0){
  156. exit(json_encode(array(
  157. 'code' => 1,
  158. 'msg' => "未查询到数据"
  159. )));
  160. }
  161. exit(json_encode(array(
  162. 'code' => 0,
  163. 'msg' => "",
  164. 'count' => $count,
  165. 'data' => $list
  166. )));
  167. }
  168. // 申请注册经纪人
  169. public function fagentList()
  170. {
  171. return view('agent/fagentlist');
  172. }
  173. public function fagentForm()
  174. {
  175. $id = input('id/d, 0');
  176. $fagent = AgentFormModel::findOrEmpty($id);
  177. return view('agent/fagentform',[
  178. 'fagent' => $fagent
  179. ]);
  180. }
  181. public function editFagent()
  182. {
  183. $id = input('id/d');
  184. $fagent = AgentFormModel::findOrEmpty($id);
  185. $fagent->save([
  186. 'realname' => input('realname/s', ""),
  187. 'mobile' => input('mobile/s', ""),
  188. 'address' => input('address/s', ""),
  189. 'idcard' => input('idcard/s', ""),
  190. 'recommender' => input('recommender/s', ""),
  191. 'status' => input('status/d', 1),
  192. 'remark' => input('remark/s', ""),
  193. 'createtime' => input('createtime/s', ""),
  194. ]);
  195. exit(json_encode(array(
  196. 'code' => 0
  197. )));
  198. }
  199. public function fieldFagent()
  200. {
  201. $id = input('id/d',0);
  202. $info = AgentFormModel::findOrEmpty($id);
  203. if ($info->isEmpty()){
  204. exit(json_encode(array(
  205. 'code' => 1,
  206. 'msg' => "信息不存在"
  207. )));
  208. }else{
  209. $info->save([
  210. input('field/s') => input('value')
  211. ]);
  212. }
  213. exit(json_encode(array(
  214. 'code' => 0
  215. )));
  216. }
  217. public function delFagent()
  218. {
  219. $idarr = input('idarr/a');
  220. $fagent = AgentFormModel::whereIn('id',$idarr)->select();
  221. $result = $fagent->delete();
  222. if ($result){
  223. exit(json_encode(array(
  224. 'code' => 0,
  225. 'msg' => ""
  226. )));
  227. }
  228. exit(json_encode(array(
  229. 'code' => 1,
  230. 'msg' => "删除失败,请稍后重试"
  231. )));
  232. }
  233. public function listFagent()
  234. {
  235. $limit = input('limit');
  236. $page = input('page');
  237. $map = array();
  238. $keywords = input('keywords/s');
  239. if (!empty($keywords)){
  240. $map[] =['realname|mobile', 'like', '%'.$keywords.'%'];
  241. }
  242. $status = input('status/d');
  243. if (!empty($status)){
  244. $map[] = ['status', '=', $status];
  245. }
  246. $list = AgentFormModel::where($map)->order('id','DESC')->limit($limit)->page($page)->append(['status_text'])->select();
  247. $count = AgentFormModel::where($map)->count();
  248. if ($count==0){
  249. exit(json_encode(array(
  250. 'code' => 1,
  251. 'msg' => "未查询到数据"
  252. )));
  253. }
  254. exit(json_encode(array(
  255. 'code' => 0,
  256. 'msg' => "",
  257. 'count' => $count,
  258. 'data' => $list
  259. )));
  260. }
  261. }