Worker.php 6.1 KB

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