Worker.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace app\mobile\controller;
  3. use app\common\model\Agent as AgentModel;
  4. use app\common\model\OutRecruit as OutRecruitModel;
  5. use app\common\model\Broker as BrokerModel;
  6. use app\common\model\OutRecruitReport;
  7. use app\common\model\OutResume as OutResumeModel;
  8. use app\mobile\MobileBaseController;
  9. use app\mobile\validate\WorkerReportValidate;
  10. use think\exception\ValidateException;
  11. use think\facade\Db;
  12. class Worker extends MobileBaseController
  13. {
  14. /**
  15. * 招聘信息
  16. */
  17. public function index()
  18. {
  19. $agent_id = session('mobile.agent_id');
  20. if (empty($agent_id)) {
  21. $agent_id = input('id/d', 0);
  22. if (empty($agent_id)) {
  23. jump('门店不存在');
  24. }
  25. session('mobile.agent_id', $agent_id);
  26. }
  27. $agent = AgentModel::where([
  28. ['id', '=', $agent_id],
  29. ['type', '=', 2],
  30. ['status', '=', 1],
  31. ])->find();
  32. if (empty($agent)) {
  33. session('mobile.agent_id', null);
  34. jump('门店不存在');
  35. }
  36. return view('worker/index', [
  37. 'agent' => $agent,
  38. ]);
  39. // return view('index/index');
  40. }
  41. public function listRecruit()
  42. {
  43. $map = $this->dealLikeInput(['keyword' => 'title|company_name']);
  44. $map[] = ['status', '=', 1];
  45. $list = OutRecruitModel::where($map)
  46. ->order(['priority' => 'desc', 'id' => 'desc'])
  47. ->limit(input('limit', 10))
  48. ->page(input('page', 1))
  49. ->select();
  50. ajax_success($list);
  51. }
  52. public function recruitDetail()
  53. {
  54. $agent = $this->get_agent();
  55. $id = input('id/d', 0);
  56. if (empty($id)) {
  57. jump('招聘不存在');
  58. }
  59. $info = OutRecruitModel::find($id);
  60. if (empty($info) || $info['status'] != 1) {
  61. jump('该信息不存在或已下架');
  62. }
  63. $broker = BrokerModel::where('agentid', $agent['id'])->find();
  64. $has_broker = empty($broker) ? 'false' : 'true';
  65. return view('worker/recruit_detail', ['info' => $info, 'has_broker' => $has_broker]);
  66. }
  67. /**
  68. * 报备
  69. */
  70. public function report()
  71. {
  72. $id = input('id/d', 0);
  73. if (empty($id)) {
  74. jump('招聘不存在');
  75. }
  76. $info = OutRecruitModel::find($id);
  77. if (empty($info) || $info['status'] != 1) {
  78. jump('该信息不存在或已下架');
  79. }
  80. $agent = $this->get_agent();
  81. $broker = BrokerModel::field(['title as text', 'id as value'])->where([
  82. ['agentid', '=', $agent['id']],
  83. ['status', '=', 1],
  84. ['type', '=', 3],
  85. ])->select();
  86. !empty($broker->isEmpty()) && jump('该门店暂无经纪人,无法报备');
  87. return view('worker/report', [
  88. 'broker_list' => $broker,
  89. 'info' => $info,
  90. ]);
  91. }
  92. public function reportPost()
  93. {
  94. $data = input('post.');
  95. $agent = $this->get_agent();
  96. try {
  97. validate(WorkerReportValidate::class)->check($data);
  98. } catch (ValidateException $e) {
  99. ajax_return(1, $e->getError());
  100. }
  101. //简历
  102. $resume = OutResumeModel::with(['broker'])->where('mobile', $data['mobile'])->find();
  103. $resume && ajax_return(1, '您已有经纪人,请找经纪人报备!经纪人信息' . $resume['broker']['title'] . '(<a href="tel:' . $resume['broker']['mobile'] . '">' . $resume['broker']['mobile'] . '</a>)');
  104. //报备记录
  105. $report = OutRecruitReport::with(['broker'])->where('mobile', $data['mobile'])->where('recruit_id', $data['recruit_id'])->find();
  106. $report && ajax_return(1, '您已有经纪人,请找经纪人报备!经纪人信息' . $report['broker']['title'] . '(<a href="tel:' . $report['broker']['mobile'] . '">' . $report['broker']['mobile'] . '</a>)');
  107. //添加报备信息
  108. if (empty($data['brokerid'])) {
  109. $broker = BrokerModel::where([
  110. ['agentid', '=', $agent['id']],
  111. ['status', '=', 1],
  112. ['type', '=', 3],
  113. ])->order(Db::raw('RAND()'))->find();
  114. $data['brokerid'] = $broker['id'];
  115. } else {
  116. $broker = BrokerModel::find($data['brokerid']);
  117. }
  118. $data['workerid'] = $broker['workerid'];
  119. $data['agentid'] = $broker['agentid'];
  120. $data['createtime'] = time();
  121. OutRecruitReport::create($data);
  122. ajax_return(0, '报名成功,经纪人:' . $broker['title'] . '(<a href="tel:' . $broker['mobile'] . '">' . $broker['mobile'] . '</a>)', '/mobile/worker/index');
  123. }
  124. /**
  125. * 经纪人
  126. */
  127. public function broker()
  128. {
  129. return view('worker/broker');
  130. }
  131. public function listBroker()
  132. {
  133. $agent = $this->get_agent();
  134. $list = BrokerModel::where('agentid', $agent['id'])
  135. ->where('status', 1)
  136. ->limit(input('limit', 10))
  137. ->page(input('page', 1))
  138. ->select();
  139. ajax_success($list);
  140. }
  141. /**
  142. * 报备查询
  143. */
  144. public function reportFind()
  145. {
  146. $mobile = input('mobile');
  147. if (empty($mobile)) {
  148. return view('worker/report_find');
  149. }
  150. $report = OutRecruitReport::where('mobile', $mobile)->find();
  151. if (empty($report)) {
  152. ajax_return(1, '暂无信息');
  153. }
  154. $broker = BrokerModel::find($report['brokerid']);
  155. ajax_success($broker);
  156. }
  157. public function listReport()
  158. {
  159. $map = $this->dealEqualInput(['mobile']);
  160. $list = OutRecruitReport::with(['recruit'])
  161. ->where($map)
  162. ->order(['id' => 'desc'])
  163. ->limit(input('limit', 10))
  164. ->page(input('page', 1))
  165. ->select();
  166. ajax_success($list);
  167. }
  168. private function get_agent()
  169. {
  170. $agent_id = session('mobile.agent_id');
  171. if (empty($agent_id)) {
  172. jump('门店不存在');
  173. }
  174. $agent = AgentModel::where([
  175. ['id', '=', $agent_id],
  176. ['type', '=', 2],
  177. ['status', '=', 1],
  178. ])->find();
  179. if (empty($agent)) {
  180. session('mobile.agent_id', null);
  181. jump('门店不存在');
  182. }
  183. return $agent;
  184. }
  185. }