Worker.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace app\mobile\controller;
  3. use app\common\model\Agent as AgentModel;
  4. use app\common\model\Config;
  5. use app\common\model\OutRecruit as OutRecruitModel;
  6. use app\common\model\Broker as BrokerModel;
  7. use app\common\model\OutRecruitReport;
  8. use app\common\model\OutResume as OutResumeModel;
  9. use app\mobile\MobileBaseController;
  10. use app\mobile\validate\WorkerReportValidate;
  11. use think\exception\ValidateException;
  12. use think\facade\Db;
  13. class Worker extends MobileBaseController
  14. {
  15. /**
  16. * 招聘信息
  17. */
  18. public function index()
  19. {
  20. $agent_id = session('mobile.agent_id');
  21. if (empty($agent_id)) {
  22. $agent_id = input('id/d', 0);
  23. if (empty($agent_id)) {
  24. jump('门店不存在');
  25. }
  26. session('mobile.agent_id', $agent_id);
  27. }
  28. $agent = AgentModel::where([
  29. ['id', '=', $agent_id],
  30. ['type', '=', 2],
  31. ['status', '=', 1],
  32. ])->find();
  33. if (empty($agent)) {
  34. session('mobile.agent_id', null);
  35. jump('门店不存在');
  36. }
  37. return view('worker/index', [
  38. 'agent' => $agent,
  39. ]);
  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. return view('worker/report', [
  85. 'broker_list' => $broker,
  86. 'info' => $info,
  87. ]);
  88. }
  89. public function reportPost()
  90. {
  91. $data = input('post.');
  92. $agent = $this->get_agent();
  93. try {
  94. validate(WorkerReportValidate::class)->check($data);
  95. } catch (ValidateException $e) {
  96. ajax_return(1, $e->getError());
  97. }
  98. //简历
  99. $resume = OutResumeModel::with(['broker'])->where('mobile', $data['mobile'])->find();
  100. $resume && ajax_return(1, '您已有经纪人,请找经纪人报备!经纪人信息' . $resume['broker']['title'] . '(<a href="tel:' . $resume['broker']['mobile'] . '">' . $resume['broker']['mobile'] . '</a>)');
  101. //报备记录
  102. $report = OutRecruitReport::with(['broker'])->where('mobile', $data['mobile'])->where('recruit_id', $data['recruit_id'])->find();
  103. $report && ajax_return(1, '您已有经纪人,请找经纪人报备!经纪人信息' . $report['broker']['title'] . '(<a href="tel:' . $report['broker']['mobile'] . '">' . $report['broker']['mobile'] . '</a>)');
  104. //添加报备信息
  105. if (empty($data['brokerid'])) {
  106. $broker = BrokerModel::where([
  107. ['agentid', '=', $agent['id']],
  108. ['status', '=', 1],
  109. ['type', '=', 3],
  110. ])->order(Db::raw('RAND()'))->find();
  111. if (empty($broker)) {
  112. $data['brokerid'] = Config::getConfigValue('default_broker');
  113. $broker = BrokerModel::find($data['brokerid']);
  114. } else {
  115. $data['brokerid'] = $broker['id'];
  116. }
  117. } else {
  118. $broker = BrokerModel::find($data['brokerid']);
  119. }
  120. $data['workerid'] = $broker['workerid'];
  121. $data['agentid'] = $broker['agentid'];
  122. $data['createtime'] = time();
  123. OutRecruitReport::create($data);
  124. ajax_return(0, '报名成功,经纪人:' . $broker['title'] . '(<a href="tel:' . $broker['mobile'] . '">' . $broker['mobile'] . '</a>)', '/mobile/worker/index');
  125. }
  126. /**
  127. * 经纪人
  128. */
  129. public function broker()
  130. {
  131. return view('worker/broker');
  132. }
  133. public function listBroker()
  134. {
  135. $agent = $this->get_agent();
  136. $list = BrokerModel::where('agentid', $agent['id'])
  137. ->where('status', 1)
  138. ->limit(input('limit', 10))
  139. ->page(input('page', 1))
  140. ->select();
  141. ajax_success($list);
  142. }
  143. /**
  144. * 报备查询
  145. */
  146. public function reportFind()
  147. {
  148. $mobile = input('mobile');
  149. if (empty($mobile)) {
  150. return view('worker/report_find');
  151. }
  152. $report = OutRecruitReport::where('mobile', $mobile)->find();
  153. if (empty($report)) {
  154. ajax_return(1, '暂无信息');
  155. }
  156. $broker = BrokerModel::find($report['brokerid']);
  157. ajax_success($broker);
  158. }
  159. public function listReport()
  160. {
  161. $map = $this->dealEqualInput(['mobile']);
  162. $list = OutRecruitReport::with(['recruit'])
  163. ->where($map)
  164. ->order(['id' => 'desc'])
  165. ->limit(input('limit', 10))
  166. ->page(input('page', 1))
  167. ->select();
  168. ajax_success($list);
  169. }
  170. private function get_agent()
  171. {
  172. $agent_id = session('mobile.agent_id');
  173. if (empty($agent_id)) {
  174. jump('门店不存在');
  175. }
  176. $agent = AgentModel::where([
  177. ['id', '=', $agent_id],
  178. ['type', '=', 2],
  179. ['status', '=', 1],
  180. ])->find();
  181. if (empty($agent)) {
  182. session('mobile.agent_id', null);
  183. jump('门店不存在');
  184. }
  185. return $agent;
  186. }
  187. }