Broker.php 6.5 KB

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