Worker.php 6.1 KB

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