Broker.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <?php
  2. namespace app\mainapp\controller;
  3. use app\mainapp\BaseController;
  4. use app\common\model\Param as ParamModel;
  5. use app\common\model\User as UserModel;
  6. use app\common\model\UserFollow as UserFollowModel;
  7. use app\common\model\Broker as BrokerModel;
  8. use app\common\model\BrokerForm as BrokerFormModel;
  9. use app\common\model\DemandSnatch as DemandSnatchModel;
  10. use app\common\model\DemandReport as DemandReportModel;
  11. use app\common\validate\DemandReport as DemandReportValidate;
  12. use think\exception\ValidateException;
  13. /*use app\common\model\ReportEntry as ReportEntryModel;
  14. use app\common\model\ReportFactory as ReportFactoryModel;
  15. use app\common\model\ReportOrder as ReportOrderModel;
  16. use app\common\model\ReportOrderlog as ReportOrderlogModel;*/
  17. class Broker extends BaseController
  18. {
  19. public function getListBroker()
  20. {
  21. $ppage = input('ppage/d', 1);
  22. $psize = input('psize/d', 20);
  23. $map = [];
  24. $map[] = ['status', '=', 1];
  25. $searchval = input('searchval/s', "");
  26. if (!empty($searchval)) {
  27. $map[] = ['title', 'like', '%' . $searchval . '%'];
  28. }
  29. $district = input('district/s', "");
  30. if (!empty($district)) {
  31. $map[] = ['district', '=', $district];
  32. }
  33. $plist = BrokerModel::with(['muser'])->where($map)->order(['id' => 'desc'])->page($ppage)->limit($psize)->select();
  34. page_result(0, "", [
  35. 'plist' => $plist,
  36. 'pstatus' => $psize > count($plist) ? 'noMore' : 'more',
  37. ]);
  38. }
  39. // 申请注册经纪人
  40. public function pageForm()
  41. {
  42. $param = ParamModel::where(1)->find();
  43. page_result(0, "", [
  44. 'param' => $param,
  45. ]);
  46. }
  47. public function regBroker()
  48. {
  49. $realname = input('realname/s', "");
  50. $mobile = input('mobile/s', "");
  51. $address = input('address/s', "");
  52. $idcard = input('idcard/s', "");
  53. $recommender = input('recommender/s', "");
  54. if (empty($realname) || empty($mobile) || empty($address) || empty($idcard)) {
  55. page_result(1, "姓名、手机号、当前住址、身份证号均不能为空。");
  56. }
  57. $form = new BrokerFormModel;
  58. $form->save([
  59. 'realname' => $realname,
  60. 'mobile' => $mobile,
  61. 'address' => $address,
  62. 'idcard' => $idcard,
  63. 'recommender' => $recommender,
  64. 'status' => 1,
  65. 'remark' => "",
  66. 'createtime' => time(),
  67. ]);
  68. page_result(0, "", []);
  69. }
  70. // 订单信息
  71. public function listOrder()
  72. {
  73. $brokerid = input('brokerid/d', 0);
  74. if (empty($brokerid)) {
  75. page_result(0, "", [
  76. 'plist' => [],
  77. 'pstatus' => 'noMore',
  78. ]);
  79. }
  80. $broker = BrokerModel::find($brokerid);
  81. if (empty($broker)) {
  82. page_result(0, "", [
  83. 'plist' => [],
  84. 'pstatus' => 'noMore',
  85. ]);
  86. }
  87. $workerid = $broker->workerid;
  88. $ppage = input('ppage/d', 1);
  89. $psize = input('psize/d', 20);
  90. $map = [];
  91. $map[] = ['status', '>=', 2];
  92. $map[] = ['worker_id', '=', $workerid];
  93. $plist = DemandSnatchModel::with(['demand' => ['worker']])->where($map)->order(['status' => 'ASC', 'id' => 'DESC'])->page($ppage)->limit($psize)->append(['status_text'])->select();
  94. foreach ($plist as $v) {
  95. $snatch_num = DemandReportModel::where('snatchid', $v['id'])->count();
  96. $v['snatch_num'] = $snatch_num;
  97. }
  98. page_result(0, "", [
  99. 'plist' => $plist,
  100. 'pstatus' => $psize > count($plist) ? 'noMore' : 'more',
  101. ]);
  102. }
  103. // 报备信息
  104. public function getOrder()
  105. {
  106. $id = input('id/d', 0);
  107. $brokerid = input('brokerid/d', 0);
  108. $order = DemandSnatchModel::with(['demand' => ['worker']])->where(['id' => $id])->append(['status_text'])->find();
  109. $order_log = DemandReportModel::where('brokerid', $brokerid)->where('snatchid', $id)->select();
  110. page_result(0, "", [
  111. 'order' => $order,
  112. 'order_log' => $order_log,
  113. ]);
  114. }
  115. public function addReport()
  116. {
  117. $snatchid = input('snatchid/d', 0);
  118. $snatch = DemandSnatchModel::where('id', '=', $snatchid)->findOrEmpty();
  119. if ($snatch->isEmpty()) {
  120. page_result(1, "订单不存在。");
  121. }
  122. if ($snatch['status'] != 2) {
  123. exit(json_encode([
  124. 'code' => 1,
  125. 'msg' => "该订单暂时无法报备",
  126. ]));
  127. }
  128. $brokerid = input('brokerid/d', 0);
  129. $broker = BrokerModel::where('id', '=', $brokerid)->findOrEmpty();
  130. if ($broker->isEmpty()) {
  131. page_result(1, "经纪人信息不存在。");
  132. }
  133. $snatch_num = DemandReportModel::where('snatchid', $snatchid)->count();
  134. if ($snatch_num >= $snatch['num']) {
  135. exit(json_encode([
  136. 'code' => 1,
  137. 'msg' => "人数已满",
  138. ]));
  139. }
  140. //数据检验
  141. $data = [
  142. 'demandid' => $snatch['demand_id'],
  143. 'snatchid' => $snatchid,
  144. 'workerid' => $broker['workerid'],
  145. 'agentid' => $broker['agentid'],
  146. 'brokerid' => $broker['id'],
  147. 'realname' => input('realname/s', ""),
  148. 'mobile' => input('mobile/s', ""),
  149. 'idcard' => input('idcard/s', ""),
  150. 'arrivetime' => input('arrivetime/s', ""),
  151. 'remark' => input('remark/s', ""),
  152. 'retremark' => "",
  153. 'createtime' => date("Y-m-d H:i:s"),
  154. ];
  155. try {
  156. validate(DemandReportValidate::class)->check($data);
  157. } catch (ValidateException $e) {
  158. page_result(1, $e->getError());
  159. }
  160. $check = DemandReportModel::where('snatchid', $snatchid)->where('mobile', $data['mobile'])->whereOr('idcard', $data['idcard'])->find();
  161. if (!empty($check)) {
  162. exit(json_encode([
  163. 'code' => 1,
  164. 'msg' => "该手机号或身份证号已报备,请勿重复",
  165. ]));
  166. }
  167. DemandReportModel::create($data);
  168. if ($snatch_num + 1 == $snatch['num']) {
  169. $snatch->status == 3;
  170. $snatch->save();
  171. }
  172. page_result(0, "", []);
  173. }
  174. // 报备信息
  175. /*public function getOrder()
  176. {
  177. $orderid = input('orderid/d',0);
  178. $agentid = input('agentid/d',0);
  179. $order = ReportOrderModel::with(['reportFactory'])->where(['id'=>$orderid])->find();
  180. $orderlog = ReportOrderlogModel::where(['agentid'=>$agentid,'orderid'=>$orderid])->order(['id'=>"DESC"])->select();
  181. ReportOrderlogModel::update(['status' => 2], ['agentid'=>$agentid,'orderid'=>$orderid]);
  182. page_result(0, "", array(
  183. 'order' => $order,
  184. 'orderlog' => $orderlog
  185. ));
  186. }
  187. // 订单信息
  188. public function listOrder()
  189. {
  190. $brokerid = input('brokerid/d',0);
  191. $broker = BrokerModel::findOrEmpty($brokerid);
  192. $agentid = $broker->agentid;
  193. $ppage = input('ppage/d', 1);
  194. $psize = input('psize/d', 20);
  195. $map = array();
  196. $map[] = ['ReportOrder.status', '>', 1];
  197. $plist = ReportOrderModel::hasWhere('reportOrderlog',['agentid'=>$agentid])->with(['reportFactory'])->where($map)->order(['status'=>'ASC','id'=>'DESC'])->page($ppage)->limit($psize)->select()->toArray();
  198. foreach($plist as $key=>$val){
  199. $plist[$key]['log'] = ReportOrderlogModel::where(['agentid'=>$agentid,'orderid'=>$val['id']])->order(['id'=>'DESC'])->findOrEmpty()->toArray();
  200. }
  201. page_result(0, "", array(
  202. 'plist' => $plist,
  203. 'pstatus' => $psize > count($plist) ? 'noMore' : 'more'
  204. ));
  205. }
  206. // 数据信息
  207. public function pageBroker()
  208. {
  209. $brokerid = input('brokerid/d', 0);
  210. $stime = strtotime(date("Y-m-d"),time());
  211. $tuserCount = UserModel::where('brokerid', '=', $brokerid)->where('createtime','between',[$stime,$stime+86400])->count();
  212. $userCount = UserModel::where('brokerid', '=', $brokerid)->count();
  213. $tentryCount = ReportEntryModel::where('brokerid', '=', $brokerid)->where('createtime','between',[$stime,$stime+86400])->count();
  214. $entryCount = ReportEntryModel::where('brokerid', '=', $brokerid)->count();
  215. page_result(0, "", array('countobj' => array(
  216. 'tuser' => $tuserCount,
  217. 'user' => $userCount,
  218. 'tentry' => $tentryCount,
  219. 'entry' => $entryCount
  220. )));
  221. }
  222. // 报备信息
  223. public function getEntry()
  224. {
  225. $entryid = input('entryid/d',0);
  226. $brokerid = input('brokerid/d',0);
  227. $entry = ReportEntryModel::with(['reportFactory'])->where(['brokerid'=>$brokerid,'id'=>$entryid])->find();
  228. $broker = BrokerModel::with('agent')->findOrEmpty($brokerid);
  229. $factorylist = ReportFactoryModel::order(['priority'=>'desc','id'=>'desc'])->select()->toArray();
  230. $factoryidarr = ReportFactoryModel::order(['priority'=>'desc','id'=>'desc'])->column('title');
  231. page_result(0, "", array(
  232. 'entry' => $entry,
  233. 'broker' => $broker,
  234. 'factorylist' => $factorylist,
  235. 'factoryidarr' => array_values($factoryidarr),
  236. 'today' => date("Y-m-d")
  237. ));
  238. }
  239. public function statusEntry()
  240. {
  241. $entryid = input('entryid/d',0);
  242. $brokerid = input('brokerid/d',0);
  243. $entry = ReportEntryModel::with(['reportFactory'])->where('brokerid','=',$brokerid)->findOrEmpty($entryid);
  244. if ($entry->isEmpty()){
  245. page_result(1, "报备信息不存在。");
  246. }
  247. if ($entry->status > 1){
  248. page_result(1, "报备信息已确认过。");
  249. }
  250. $entry->save(['status'=>2]);
  251. page_result(0, "", array(
  252. 'entry' => $entry
  253. ));
  254. }
  255. public function deleteEntry()
  256. {
  257. $entryid = input('entryid/d',0);
  258. $brokerid = input('brokerid/d',0);
  259. $entry = ReportEntryModel::with(['reportFactory'])->where('brokerid','=',$brokerid)->findOrEmpty($entryid);
  260. if ($entry->isEmpty()){
  261. page_result(1, "报备信息不存在。");
  262. }
  263. if ($entry->status > 1){
  264. page_result(1, "报备信息已确认过,不能删除。");
  265. }
  266. $entry->delete();
  267. page_result(0, "", array());
  268. }
  269. public function addEntry()
  270. {
  271. $brokerid = input('brokerid/d',0);
  272. $broker = BrokerModel::with('agent')->findOrEmpty($brokerid);
  273. if ($broker->isEmpty()){
  274. page_result(1, "经纪人信息不存在。");
  275. }
  276. $data = array(
  277. 'workerid' => $broker->workerid,
  278. 'agentid' => $broker->agentid,
  279. 'brokerid' => $brokerid,
  280. 'factoryid' => input('factoryid/d', 0),
  281. 'realname' => input('realname/s', ""),
  282. 'mobile' => input('mobile/s', ""),
  283. 'idcard' => input('idcard/s', ""),
  284. 'gender' => input('gender/s', ""),
  285. 'nation' => input('nation/s', ""),
  286. 'address' => input('address/s', ""),
  287. 'startdate' => input('startdate/s', ""),
  288. 'enddate' => input('enddate/s', ""),
  289. 'reftype' => input('reftype/s', ""),
  290. 'refpolicy' => input('refpolicy/s', ""),
  291. 'agentremark' => input('agentremark/s', ""),
  292. 'status' => input('status/d', ""),
  293. 'remark' => "",
  294. 'createtime' => time()
  295. );
  296. $entry = new ReportEntryModel;
  297. $entry->save($data);
  298. $newentry = ReportEntryModel::with(['reportFactory'])->where('brokerid','=',$brokerid)->find($entry->id);
  299. page_result(0, "", array(
  300. 'entry' => $newentry
  301. ));
  302. }*/
  303. public function setIdcard()
  304. {
  305. $picpath = input('picpath/s', "");
  306. $picpath = root_path() . "public" . $picpath;
  307. $idcard = aliyun_ocr_idcard($picpath);
  308. if ($idcard == false) {
  309. page_result(1, "身份证信息识别失败。");
  310. }
  311. page_result(0, "", [
  312. 'idcard' => $idcard,
  313. ]);
  314. }
  315. /*public function pageEntry()
  316. {
  317. $brokerid = input('brokerid/d',0);
  318. $statuslist = array(
  319. array('value'=>"", 'title'=>'状态不限'),
  320. array('value'=>1, 'title'=>'待确认'),
  321. array('value'=>2, 'title'=>'已确认'),
  322. array('value'=>3, 'title'=>'已入职'),
  323. array('value'=>4, 'title'=>'未通过')
  324. );
  325. $factorylist = ReportFactoryModel::field('id as value, title, priority')->order(['priority'=>'desc','id'=>'desc'])->select()->toArray();
  326. array_unshift($factorylist, array('value'=>"", 'title'=>'工厂不限'));
  327. page_result(0, "", array(
  328. 'statuslist' => $statuslist,
  329. 'factorylist' => $factorylist
  330. ));
  331. }
  332. public function listEntry()
  333. {
  334. $ppage = input('ppage/d', 1);
  335. $psize = input('psize/d', 20);
  336. $map = array();
  337. $brokerid = input('brokerid/d', 0);
  338. $map[] = ['brokerid', '=', $brokerid];
  339. $status = input('status/d', 0);
  340. if (!empty($status)){
  341. $map[] = ['status', '=', $status];
  342. }
  343. $factoryid = input('factoryid/d', 0);
  344. if (!empty($factoryid)){
  345. $map[] = ['factoryid', '=', $factoryid];
  346. }
  347. $searchval = input('searchval/s', "");
  348. if (!empty($searchval)){
  349. $map[] =['realname|mobile', 'like', '%'.$searchval.'%', 'OR'];
  350. }
  351. $plist = ReportEntryModel::with(['reportFactory'])->where($map)->order(['id'=>'desc'])->page($ppage)->limit($psize)->select();
  352. page_result(0, "", array(
  353. 'plist' => $plist,
  354. 'pstatus' => $psize > count($plist) ? 'noMore' : 'more'
  355. ));
  356. }*/
  357. // 我的邀请
  358. public function getMyuser()
  359. {
  360. $userid = input('userid/d', 0);
  361. $brokerid = input('brokerid/d', 0);
  362. $user = UserModel::with(['userFollow'])->where('brokerid', '=', $brokerid)->findOrEmpty($userid);
  363. if ($user->isEmpty()) {
  364. page_result(1, "用户信息不存在");
  365. }
  366. page_result(0, "", [
  367. 'user' => $user,
  368. ]);
  369. }
  370. public function sendFollow()
  371. {
  372. $userid = input('userid/d', 0);
  373. $ftype = input('ftype/s', "");
  374. $remark = input('remark/s', "");
  375. if (empty($remark)) {
  376. page_result(1, "请输入跟进的具体内容。");
  377. }
  378. $followstatus = input('followstatus/d', 1);
  379. UserModel::update(['followstatus' => $followstatus], ['id' => $userid]);
  380. $data = [
  381. 'userid' => $userid,
  382. 'ftype' => $ftype,
  383. 'remark' => $remark,
  384. 'createtime' => time(),
  385. ];
  386. $follow = new UserFollowModel;
  387. $follow->save($data);
  388. $user = UserModel::with(['userFollow'])->findOrEmpty($userid);
  389. page_result(0, "", [
  390. 'user' => $user,
  391. ]);
  392. }
  393. public function listUser()
  394. {
  395. $ppage = input('ppage/d', 1);
  396. $psize = input('psize/d', 20);
  397. $map = [];
  398. $brokerid = input('brokerid/d', 0);
  399. $map[] = ['brokerid', '=', $brokerid];
  400. $followstatus = input('followstatus/d', 0);
  401. if (!empty($followstatus)) {
  402. $map[] = ['followstatus', '=', $followstatus];
  403. }
  404. $plist = UserModel::with(['userFollow'])->where($map)->order(['id' => 'desc'])->page($ppage)->limit($psize)->select();
  405. page_result(0, "", [
  406. 'plist' => $plist,
  407. 'pstatus' => $psize > count($plist) ? 'noMore' : 'more',
  408. ]);
  409. }
  410. }