Broker.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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\Broker as BrokerModel;
  8. use app\common\model\BrokerForm as BrokerFormModel;
  9. use app\common\validate\Broker as BrokerValidate;
  10. use think\exception\ValidateException;
  11. class Broker extends BaseController
  12. {
  13. public function brokerList()
  14. {
  15. $workerlist = WorkerModel::order(['id'=>'desc'])->select();
  16. $agentlist = AgentModel::order(['id'=>'desc'])->select();
  17. return view('broker/brokerlist',[
  18. 'workerlist' => $workerlist,
  19. 'agentlist' => $agentlist
  20. ]);
  21. }
  22. public function brokerForm()
  23. {
  24. $id = input('id/d, 0');
  25. $broker = BrokerModel::findOrEmpty($id);
  26. $workerlist = WorkerModel::with(['agent','muser'])->order(['id'=>'desc'])->select();
  27. return view('broker/brokerform',[
  28. 'workerlist' => $workerlist,
  29. 'broker' => $broker
  30. ]);
  31. }
  32. public function editBroker()
  33. {
  34. $id = input('id/d');
  35. $data = [
  36. 'title' => input('title/s', ""),
  37. 'mobile' => input('mobile/s', ""),
  38. 'weixin' => input('weixin/s', ""),
  39. 'qq' => input('qq/s', ""),
  40. 'province' => input('province/s', ""),
  41. 'city' => input('city/s', ""),
  42. 'district' => input('district/s', ""),
  43. 'details' => input('details/s', ""),
  44. 'powerreport' => input('powerreport/d')==1 ? 1 : 2,
  45. 'status' => input('status/d')==1 ? 1 : 2
  46. ];
  47. if (empty($id)){
  48. $vdata = array(
  49. 'id' => $id,
  50. 'mobile' => input('mobile/s')
  51. );
  52. try {
  53. validate(BrokerValidate::class)->check($vdata);
  54. } catch (ValidateException $e) {
  55. exit(json_encode(array(
  56. 'code' => 1,
  57. 'msg' => $e->getError()
  58. )));
  59. }
  60. $muser = UserModel::where(['mobile'=>input('musermobile/s', '')])->findOrEmpty();
  61. if ($muser->isEmpty()){
  62. exit(json_encode(array(
  63. 'code' => 1,
  64. 'msg' => "关联的用户不存在。"
  65. )));
  66. }
  67. $workeragentarr = explode(",", input('workeragent/s'));
  68. $workerid = isset($workeragentarr[0]) ? $workeragentarr[0] : 0;
  69. $agentid = isset($workeragentarr[1]) ? $workeragentarr[1] : 0;
  70. if ( empty($workerid) || empty($agentid) ){
  71. exit(json_encode(array(
  72. 'code' => 1,
  73. 'msg' => "请选择劳务公司和代理门店。"
  74. )));
  75. }
  76. $broker_user = BrokerModel::where('userid',$muser->id)->find();
  77. if (!empty($broker_user)) {
  78. exit(json_encode(array(
  79. 'code' => 1,
  80. 'msg' => "该用户已是经纪人。"
  81. )));
  82. }
  83. $data['userid'] = $muser->id;
  84. $data['workerid'] = $workerid;
  85. $data['agentid'] = $agentid;
  86. $data['createtime'] = time();
  87. $broker = BrokerModel::create($data);
  88. event('brokerAdd',$broker);
  89. }else{
  90. $broker = BrokerModel::find($id);
  91. $broker->save($data);
  92. }
  93. exit(json_encode(array(
  94. 'code' => 0
  95. )));
  96. }
  97. public function fieldBroker()
  98. {
  99. $id = input('id/d',0);
  100. $broker = BrokerModel::findOrEmpty($id);
  101. if ($broker->isEmpty()){
  102. exit(json_encode(array(
  103. 'code' => 1,
  104. 'msg' => "信息不存在"
  105. )));
  106. }else{
  107. $broker->save([
  108. input('field/s') => input('value')
  109. ]);
  110. }
  111. exit(json_encode(array(
  112. 'code' => 0
  113. )));
  114. }
  115. public function delBroker()
  116. {
  117. $access_admin = session('access_admin');
  118. $password = input('password');
  119. if ( $access_admin['password'] !== md5($password) ){
  120. exit(json_encode(array(
  121. 'code' => 1,
  122. 'msg' => "操作密码验证失败"
  123. )));
  124. }
  125. $idarr = input('idarr/a');
  126. $user_check = UserModel::whereIn('brokerid',$idarr)->find();
  127. if (!empty($user_check)) {
  128. exit(json_encode(array(
  129. 'code' => 1,
  130. 'msg' => "该经纪人还有下线,请先转移再删除"
  131. )));
  132. }
  133. $result = BrokerModel::whereIn('id',$idarr)->delete();
  134. if ($result){
  135. exit(json_encode(array(
  136. 'code' => 0,
  137. 'msg' => ""
  138. )));
  139. }
  140. exit(json_encode(array(
  141. 'code' => 1,
  142. 'msg' => "删除失败,请稍后重试"
  143. )));
  144. }
  145. public function listBroker()
  146. {
  147. $limit = input('limit/d',20);
  148. $page = input('page/d',1);
  149. $map = array();
  150. $keywords = input('keywords/s');
  151. if (!empty($keywords)){
  152. $map[] =['title', 'like', '%'.$keywords.'%'];
  153. }
  154. $status = input('status/d');
  155. if (!empty($status)){
  156. $map[] = ['status', '=', $status];
  157. }
  158. $list = BrokerModel::with(['worker','agent','muser'])->withCount(['user'])->where($map)->order('id','DESC')->limit($limit)->page($page)->append(['status_text','powerreport_text'])->select();
  159. $count = BrokerModel::where($map)->count();
  160. if ($count==0){
  161. exit(json_encode(array(
  162. 'code' => 1,
  163. 'msg' => "未查询到数据"
  164. )));
  165. }
  166. exit(json_encode(array(
  167. 'code' => 0,
  168. 'msg' => "",
  169. 'count' => $count,
  170. 'data' => $list
  171. )));
  172. }
  173. // 申请注册职业顾问
  174. public function fbrokerList()
  175. {
  176. return view('broker/fbrokerlist');
  177. }
  178. public function fbrokerForm()
  179. {
  180. $id = input('id/d, 0');
  181. $fbroker = BrokerFormModel::findOrEmpty($id);
  182. return view('broker/fbrokerform',[
  183. 'fbroker' => $fbroker
  184. ]);
  185. }
  186. public function editFbroker()
  187. {
  188. $id = input('id/d');
  189. $fbroker = BrokerFormModel::findOrEmpty($id);
  190. $fbroker->save([
  191. 'realname' => input('realname/s', ""),
  192. 'mobile' => input('mobile/s', ""),
  193. 'address' => input('address/s', ""),
  194. 'idcard' => input('idcard/s', ""),
  195. 'recommender' => input('recommender/s', ""),
  196. 'status' => input('status/d', 1),
  197. 'remark' => input('remark/s', ""),
  198. 'createtime' => input('createtime/s', ""),
  199. ]);
  200. exit(json_encode(array(
  201. 'code' => 0
  202. )));
  203. }
  204. public function fieldFbroker()
  205. {
  206. $id = input('id/d',0);
  207. $info = BrokerFormModel::findOrEmpty($id);
  208. if ($info->isEmpty()){
  209. exit(json_encode(array(
  210. 'code' => 1,
  211. 'msg' => "信息不存在"
  212. )));
  213. }else{
  214. $info->save([
  215. input('field/s') => input('value')
  216. ]);
  217. }
  218. exit(json_encode(array(
  219. 'code' => 0
  220. )));
  221. }
  222. public function delFbroker()
  223. {
  224. $idarr = input('idarr/a');
  225. $fbroker = BrokerFormModel::whereIn('id',$idarr)->select();
  226. $result = $fbroker->delete();
  227. if ($result){
  228. exit(json_encode(array(
  229. 'code' => 0,
  230. 'msg' => ""
  231. )));
  232. }
  233. exit(json_encode(array(
  234. 'code' => 1,
  235. 'msg' => "删除失败,请稍后重试"
  236. )));
  237. }
  238. public function listFbroker()
  239. {
  240. $limit = input('limit');
  241. $page = input('page');
  242. $map = array();
  243. $keywords = input('keywords/s');
  244. if (!empty($keywords)){
  245. $map[] =['realname|mobile', 'like', '%'.$keywords.'%'];
  246. }
  247. $status = input('status/d');
  248. if (!empty($status)){
  249. $map[] = ['status', '=', $status];
  250. }
  251. $list = BrokerFormModel::where($map)->order('id','DESC')->limit($limit)->page($page)->append(['status_text','powerreport_text'])->select();
  252. $count = BrokerFormModel::where($map)->count();
  253. if ($count==0){
  254. exit(json_encode(array(
  255. 'code' => 1,
  256. 'msg' => "未查询到数据"
  257. )));
  258. }
  259. exit(json_encode(array(
  260. 'code' => 0,
  261. 'msg' => "",
  262. 'count' => $count,
  263. 'data' => $list
  264. )));
  265. }
  266. }