JobsController.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  1. <?php
  2. namespace App\Admin\Controllers\Company;
  3. use Aix\Sms\Contracts\Smser;
  4. use App\Admin\Exports\Company\JobsExport;
  5. use App\Admin\Extensions\Tools\DialogTool;
  6. use App\Http\Controllers\Controller;
  7. use App\Models\Admin\AdminRole;
  8. use App\Models\AuditReason;
  9. use App\Models\Category;
  10. use App\Models\CategoryDistrict;
  11. use App\Models\CategoryJobs;
  12. use App\Models\Company;
  13. use App\Models\Jobs;
  14. use App\Models\JobsContact;
  15. use App\Models\Subsite;
  16. use App\Models\SubsiteJob;
  17. use App\Models\ViewJob;
  18. use App\Repositories\JobsRepository;
  19. use App\Services\Common\EmailService;
  20. use App\Services\Common\PmsService;
  21. use App\Services\Common\SmsService;
  22. use App\Services\Common\WechatService;
  23. use App\Services\SubsiteService;
  24. use Encore\Admin\Auth\Permission;
  25. use Encore\Admin\Controllers\HasResourceActions;
  26. use Encore\Admin\Facades\Admin;
  27. use Encore\Admin\Form;
  28. use Encore\Admin\Grid;
  29. use Encore\Admin\Grid\Filter\TimestampBetween;
  30. use Encore\Admin\Layout\Content;
  31. use Encore\Admin\Show;
  32. use Encore\Admin\Widgets\Table;
  33. use Illuminate\Http\Request;
  34. use Illuminate\Support\Facades\DB;
  35. use Illuminate\Support\Facades\Input;
  36. use Illuminate\Support\MessageBag;
  37. class JobsController extends Controller
  38. {
  39. use HasResourceActions;
  40. protected $jobsRepository;
  41. protected $pmsService;
  42. protected $subsiteService;
  43. protected $smsService;
  44. protected $wechatService;
  45. protected $emailService;
  46. /**
  47. * JobsController constructor.
  48. * @param JobsRepository $jobsRepository .
  49. * @param SubsiteService $subsiteService .
  50. * @param PmsService $pmsService .
  51. */
  52. public function __construct(JobsRepository $jobsRepository, PmsService $pmsService, SubsiteService $subsiteService, SmsService $smsService, WechatService $wechatService, EmailService $emailService)
  53. {
  54. $this->jobsRepository = $jobsRepository;
  55. $this->pmsService = $pmsService;
  56. $this->subsiteService = $subsiteService;
  57. $this->smsService = $smsService;
  58. $this->wechatService = $wechatService;
  59. $this->emailService = $emailService;
  60. }
  61. /**
  62. * Index interface.
  63. *
  64. * @param Content $content
  65. * @return Content
  66. */
  67. public function index(Content $content)
  68. {
  69. $grid = $this->grid()->render();
  70. return $content
  71. ->header('职位管理')
  72. ->description('列表')
  73. ->body(view('admin.jobs.index')->with('grid', $grid));
  74. }
  75. /**
  76. * Show interface.
  77. *
  78. * @param mixed $id
  79. * @param Content $content
  80. * @return Content
  81. */
  82. public function show($id, Content $content)
  83. {
  84. return $content
  85. ->header('职位管理')
  86. ->description('详情')
  87. ->body($this->detail($id));
  88. }
  89. /**
  90. * Edit interface.
  91. *
  92. * @param mixed $id
  93. * @param Content $content
  94. * @return Content
  95. */
  96. public function edit($id, Content $content)
  97. {
  98. $js = <<<ETO
  99. $(document).ready(function() {
  100. $('.radio-inline,.iCheck-helper').click(function() {
  101. var val = $(this).closest(".radio-inline").find("input:radio").val();
  102. if (val == '0') {
  103. $("input[name=wage]").parents('.form-group').hide();
  104. }
  105. else if (val == '1') {
  106. $("input[name=wage]").parents('.form-group').show();
  107. }
  108. });
  109. if($("input:radio[name='negotiable']:checked").val() == '0')
  110. {
  111. $("input[name=wage]").parents('.form-group').hide();
  112. } else {
  113. $("input[name=wage]").parents('.form-group').show();
  114. }
  115. });
  116. ETO;
  117. Admin::script($js);
  118. return $content
  119. ->header('职位管理')
  120. ->description('编辑')
  121. ->body($this->editForm($id)->edit($id));
  122. }
  123. /**
  124. * Create interface.
  125. *
  126. * @param Content $content
  127. * @return Content
  128. */
  129. public function create(Content $content)
  130. {
  131. return $content
  132. ->header('职位管理')
  133. ->description('新增')
  134. ->body($this->form($id = 0));
  135. }
  136. /**
  137. * Make a grid builder.
  138. *
  139. * @return Grid
  140. */
  141. protected function grid()
  142. {
  143. Permission::check('jobs_manager');
  144. $grid = new Grid(new Jobs);
  145. $grid->model()->with(['jobsContact', 'company'])->when(get_subsite_id() > 0, function ($query) {
  146. $query->where('subsite_id', get_subsite_id());
  147. })->when(Admin::user()->isRole(AdminRole::$consultantSlug), function ($query) {
  148. $query->whereHas('companyConsultant', function ($query) {
  149. $query->where('consultant_id', isset(Admin::user()->consultant->id) ? Admin::user()->consultant->id : -1);
  150. });
  151. })->orderByRaw('field(audit,0,2,1,3)')->orderBy('created_at', 'desc');
  152. $grid->model()->when(get_subsite_id() > 0, function ($query) {
  153. $query->where('subsite_id', get_subsite_id());
  154. })->when(Admin::user()->isRole('health'), function ($query) {
  155. $query->where('is_health',1);
  156. })->orderByRaw("field(audit,2,1,3,0)")->orderBy('id', 'desc');
  157. $grid->id('id');
  158. $grid->jobs_name('职位名称')->display(function ($jobs_name) {
  159. return "<a href=" . route(url_rewrite('AIX_jobsshow'), ['id' => $this->id]) . " target='_blank' title='" . $jobs_name . "' style='display:inline-block;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;max-width:180px'>" . $jobs_name . "</a>";
  160. })->width(200);
  161. $grid->column('promition', '推广类型')->display(function ($promition) {
  162. $stick = '';
  163. $emergency = '';
  164. if ($this->stick == 0 && $this->emergency == 0) {
  165. return "<span>无推广</span>";
  166. } else {
  167. if ($this->stick == 1) {
  168. $stick = "<span>已置顶</span>";
  169. }
  170. if ($this->emergency == 1) {
  171. $emergency = '<span>已紧急</span>';
  172. }
  173. return $stick . $emergency;
  174. }
  175. });
  176. $grid->company_name('公司名称')->display(function ($company_name) {
  177. return "<a href=" . route(url_rewrite('AIX_companyshow'), ['id' => $this->company_id]) . " title='" . $company_name . "' target='_blank' style='display:inline-block;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;max-width:200px'>" . $company_name . "</a>";
  178. })->width(200);
  179. $grid->audit('审核状态')->display(function ($audit) {
  180. switch ($audit) {
  181. case 0:
  182. // return '未审核<a class="logview" data-id='.$this->id.'><i class="fa fa-eye"></i></a>';
  183. break;
  184. case 1:
  185. return '<span style="color: green">审核通过</span><a class="logview" data-id=' . $this->id . '><i class="fa fa-eye"></i></a>';
  186. break;
  187. case 2:
  188. return '<span style="color: red">审核中<a class="logview" data-id=' . $this->id . '><i class="fa fa-eye"></i></a></span>';
  189. break;
  190. case 3:
  191. return '<span style="color: black">审核未通过</span><a class="logview" data-id=' . $this->id . '><i class="fa fa-eye"></i></a>';
  192. break;
  193. }
  194. });
  195. if (get_subsite_open()) {
  196. $grid->subsite_id('所属分站')->display(function ($subsite_id) {
  197. if ($subsite_id == 0) {
  198. return "总站";
  199. } else {
  200. try {
  201. $subsite = Subsite::findOrFail($subsite_id);
  202. return $subsite->sitename;
  203. } catch (\Exception $exception) {
  204. return "--";
  205. }
  206. }
  207. });
  208. }
  209. $grid->refresh_time('刷新时间')->display(function ($refresh_time) {
  210. return date('Y-m-d H:i:s', $refresh_time);
  211. });
  212. $grid->created_at('发布时间');
  213. $grid->tools(function ($tools) {
  214. if (Admin::user()->can('jobs_manager_refresh')) {
  215. $tools->append("<a class='btn btn-sm btn-primary btn-refresh'><i class='fa fa-refresh'></i>职位刷新</a>");
  216. }
  217. });
  218. $grid->click('点击量');
  219. $grid->actions(function ($actions) {
  220. if (Admin::user()->can('jobs_manager_edit')) {
  221. $actions->disableEdit(false);
  222. }
  223. if (Admin::user()->can('company_manager_bussiness')) {
  224. $actions->append("<button class='btn btn-primary btn-xs business' id=" . $actions->row['company_id'] . ">业务</button>");
  225. }
  226. if (Admin::user()->can('jobs_manager_delete')) {
  227. $actions->disableDelete(false);
  228. }
  229. if (Admin::user()->can('jobs_manager_audit')) {
  230. $actions->append("<button class='btn btn-primary btn-xs jobaudit' data-code=" . $actions->row['id'] . ">审核</button>");
  231. }
  232. });
  233. if (Admin::user()->can('jobs_export')) {
  234. $grid->disableExport(false); //显示导出按钮
  235. $grid->exporter(new JobsExport()); //传入自己在第1步创建的导出类
  236. }
  237. $grid->filter(function ($filter) {
  238. // 在这里添加字段过滤器
  239. $filter->column(1 / 2, function ($filter) {
  240. $filter->like('jobs_name', '职位名称');
  241. $filter->equal('company_id', '企业id');
  242. $filter->equal('audit', '职位审核')->select(['1' => '审核通过', '2' => '审核中', '3' => '审核未通过']);
  243. $filter->where(function ($query) {
  244. if ($this->input == '1') {
  245. $query->where(['stick' => 0, 'emergency' => 0]);
  246. } elseif ($this->input == 2) {
  247. $query->where(['stick' => 1]);
  248. } elseif ($this->input == 3) {
  249. $query->where(['emergency' => 1]);
  250. }
  251. }, '推广类型', 'promotion')->select([0 => '不限', 1 => '未推广', 2 => '置顶', 3 => '紧急'])->default('0');
  252. $filter->equal('valid', '有效状态')->select(['0' => '无效职位', '1' => '有效职位']);
  253. $filter->equal('is_health', '卫健系统')->select([1 => '是', 2 => '否']);
  254. $filter->equal('health_type', '卫健招聘分类')->select([1 => '高层次人才', 2 => '紧缺急需', 3 => '统招', 4 => '编外'])->default(1);
  255. $filter->equal('is_ic', '集成电路')->select([1 => '是', 2 => '否']);
  256. });
  257. $filter->column(1 / 2, function ($filter) {
  258. $filter->equal('id', '职位ID');
  259. $filter->like('company_name', '企业名称');
  260. if (get_subsite_open()) {
  261. $subsite = Subsite::where('effective', 1)->select('id', 'sitename')->get();
  262. $subsiteArr = [];
  263. if ($subsite) {
  264. $subsiteArr = $subsite->toArray();
  265. $subsiteArr = array_column($subsiteArr, 'sitename', 'id');
  266. }
  267. $subsiteArr[0] = "总站";
  268. ksort($subsiteArr);
  269. if (get_subsite_id() == 0) {
  270. $filter->equal('subsite_id', '所属分站')->select($subsiteArr);
  271. }
  272. }
  273. $filter->between('created_at', '发布时间')->datetime();
  274. $filter->use(new TimestampBetween('refresh_time', '刷新时间'))->datetime();
  275. });
  276. });
  277. //审核模态框
  278. $grid->tools(function ($tools) {
  279. if (Admin::user()->can('jobs_manager_delete')) {
  280. $tools->batch(function (Grid\Tools\BatchActions $batch) {
  281. $batch->disableDelete(false);
  282. });
  283. }
  284. if (Admin::user()->can('jobs_manager_audit')) {
  285. $form = new \Encore\Admin\Widgets\Form();
  286. $form->action(route('jobs.audit'));
  287. $form->radio('audit1', '审核状态')->options([1 => '审核通过', 3 => '审核未通过'])->default(1);
  288. $states = [
  289. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  290. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  291. ];
  292. $form->textarea('reason', '备注');
  293. $form->html("<input type='checkbox' name='is_send' checked value='1'/>站内信通知");
  294. $config = [
  295. 'button' => "审核",//添加的按钮文字
  296. 'title' => "将所选职位",//弹窗标题
  297. 'dialog_cancel' => "取消",//取消文字
  298. 'dialog_ok' => "确认",//确认文字
  299. 'is_batch' => true,//是否批量操作,如果是批量操作则提交表单时会带上ids参数
  300. ];
  301. $tools->append(new DialogTool($form, $config));
  302. }
  303. });
  304. return $grid;
  305. }
  306. /**
  307. * Make a show builder.
  308. *
  309. * @param mixed $id
  310. * @return Show
  311. */
  312. protected function detail($id)
  313. {
  314. $show = new Show(Jobs::findOrFail($id));
  315. $jobs = Jobs::findOrFail($id);
  316. $show->id('ID');
  317. $show->jobs_name('职位名称');
  318. $show->valid('在招状态')->as(function ($valid) {
  319. switch ($valid) {
  320. case 1:
  321. return "在招";
  322. break;
  323. case 0:
  324. return '关闭';
  325. break;
  326. }
  327. });
  328. $show->audit('审核状态')->as(function ($audit) {
  329. switch ($audit) {
  330. case 1:
  331. return "审核通过";
  332. break;
  333. case 2:
  334. return "审核中";
  335. break;
  336. case 3:
  337. return "审核未通过";
  338. break;
  339. case 0:
  340. break;
  341. }
  342. });
  343. $show->nature('职位性质')->as(function ($nature) {
  344. if (!$nature) {
  345. return '不限';
  346. } else {
  347. return get_category($nature);
  348. }
  349. });
  350. $show->ygxs('用工形式')->as(function ($ygxs) {
  351. if (isset(Category::categoryType('AIX_ygxs')[$ygxs])) {
  352. return Category::categoryType('AIX_ygxs')[$ygxs];
  353. } else {
  354. return "";
  355. }
  356. });
  357. $show->techlevel('技能等级')->as(function ($techlevel) {
  358. if (isset(Category::categoryType('AIX_techlevel')[$techlevel])) {
  359. return Category::categoryType('AIX_techlevel')[$techlevel];
  360. } else {
  361. return "";
  362. }
  363. });
  364. if ($jobs->ygxs != 363) { //不等于小时工显示
  365. $show->syq('试用期时间')->as(function ($syq) {
  366. if (isset(Category::categoryType('zs_syq')[$syq])) {
  367. return Category::categoryType('zs_syq')[$syq];
  368. } else {
  369. return "";
  370. }
  371. });
  372. if ($jobs->syq != 367) { //试用期无不显示
  373. $show->syqxz_min('试用期薪资');
  374. }
  375. } else {
  376. $show->wage_min('小时工薪资')->as(function ($wage_min) {
  377. return $wage_min . "元/小时";
  378. });
  379. }
  380. /**
  381. * 比较坑的Show 关联,必须要全小写,如果你关联的和你获取名字一样那直接不显示....
  382. **/
  383. $show->jobscontact()->contact('联系人')->as(function ($contact) {
  384. return $contact->contact;
  385. });
  386. $show->jobscontact()->contact_show('联系人是否公开')->as(function ($contact) {
  387. return $contact->contact_show ? "公开" : "不公开";
  388. });
  389. $show->jobscontact()->telephone('电话')->as(function ($contact) {
  390. return $contact->telephone;
  391. });
  392. $show->jobscontact()->telephone_show('电话是否公开')->as(function ($contact) {
  393. return $contact->telephone_show ? "公开" : "不公开";
  394. });
  395. $show->jobscontact()->email('邮箱')->as(function ($contact) {
  396. return $contact->email;
  397. });
  398. $show->jobscontact()->email_show('邮箱是否公开')->as(function ($contact) {
  399. return $contact->email_show ? "公开" : "不公开";
  400. });
  401. $show->category('职位分类')->as(function ($category) {
  402. return get_job_category_cn($this->topclass . '.' . $category . '.' . $this->subclass);
  403. });
  404. $show->subsite_id('所属分站')->as(function ($subsite_id) {
  405. if ($subsite_id == 0) {
  406. return "总站";
  407. } else {
  408. $subsite = Subsite::findOrFail($subsite_id);
  409. return $subsite->sitename;
  410. }
  411. });
  412. $show->district('工作地区')->as(function ($district) {
  413. return get_district_cn($district);
  414. });
  415. $show->negotiable('是否面议')->as(function ($negotiable) {
  416. if ($negotiable) {
  417. return '是';
  418. } else {
  419. return '否';
  420. }
  421. });
  422. if ($jobs->wage == -1) {
  423. $show->wage_cn('薪资待遇')->as(function () {
  424. return $this->wage_min . '~' . $this->wage_max . '/月';
  425. });
  426. } elseif ($jobs->wage == 0) {
  427. $show->wage_cn('薪资待遇')->as(function () {
  428. return "面议";
  429. });
  430. } else {
  431. $show->wage_cn('薪资待遇')->as(function () {
  432. return get_category($this->wage);
  433. });
  434. }
  435. $show->department('所属部门');
  436. $show->education('学历要求')->as(function ($education) {
  437. if ($education) {
  438. return get_category($education);
  439. } else {
  440. return '不限';
  441. }
  442. });
  443. $show->experience('工作经验')->as(function ($experience) {
  444. if ($experience) {
  445. return get_category($experience);
  446. } else {
  447. return '不限';
  448. }
  449. });
  450. $show->sex('性别要求')->as(function ($sex) {
  451. if (!$sex) {
  452. return '不限';
  453. } else {
  454. return $sex == 1 ? "男" : "女";
  455. }
  456. });
  457. $show->amount('招聘人数');
  458. $show->tag('职位亮点')->as(function ($tag) {
  459. $tagid = implode(',', $tag);
  460. if ($tagid) {
  461. return get_tag_cn($tagid);
  462. } else {
  463. return '';
  464. }
  465. });
  466. $show->jobs_content('职位描述');
  467. $show->created_at('创建时间');
  468. $show->updated_at('更新时间');
  469. return $show;
  470. }
  471. /**
  472. * Make a form builder.
  473. *
  474. * @return Form
  475. */
  476. protected function editForm($id)
  477. {
  478. Permission::check('jobs_manager_edit');
  479. $form = new Form(new Jobs);
  480. $form->tab('职位信息', function (Form $form) use ($id) {
  481. $jobsData = Jobs::where('id', $id)->select('audit', 'negotiable', 'age', 'topclass', 'category', 'subclass', 'district', 'wage', 'wage_min', 'wage_max')->first()->toArray();
  482. session(["jobsData" => $jobsData]);
  483. if ($jobsData['district']) {
  484. $district = string_to_array('.', $jobsData['district']);
  485. }
  486. $form->display('id');
  487. $form->text('jobs_name', '职位名称')->rules(['required'], ['required' => '请填写职位名称'])->setMustMark();
  488. $form->display('company_name', '公司名称');
  489. $form->radio('display', '在招状态')->options([1 => '在招', 2 => '关闭']);
  490. $form->radio('audit', '审核状态')->options([1 => '审核通过', 2 => '审核中', 3 => '审核未通过']);
  491. $jobsNature = Category::categoryType('AIX_jobs_nature');
  492. $jobsNature[0] = '不限';
  493. $form->radio('nature', '职位性质')->options($jobsNature);
  494. // if (get_subsite_id()==0 && get_subsite_open()) {
  495. // $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id');
  496. // if ($subsites) {
  497. // $relations = SubsiteJob::where(['jobs_id'=>$id])->get()->pluck('subsite_id')->toArray();
  498. // $form->multipleSelect('relate_subsites', '同步分站')->options($subsites)->default($relations);
  499. //
  500. // }
  501. // } else {
  502. // $form->hidden('relate_subsites');
  503. // }
  504. // $form->hidden('subsite_id')->value(get_subsite_id());
  505. // $form->select('ygxs', '用工形式')->options(Category::categoryType('AIX_ygxs'))->setMustMark();
  506. // $form->select('techlevel', '技能等级')->options(Category::categoryType('AIX_techlevel'))->setMustMark();
  507. $form->select('topclass', '职位大类')->options(CategoryJobs::List()->pluck('name', 'id'))->load('category', admin_base_path('/sys/categoryJobs/category'))->rules('required', ['required' => '请选择职位大类'])->setMustMark();
  508. $form->select('category', '职位中类')->options(CategoryJobs::category($jobsData['topclass']))->load('subclass', admin_base_path('/sys/categoryJobs/category'))->rules('required', ['required' => '请选择职位中类'])->setMustMark();
  509. $form->select('subclass', '职位小类')->options(CategoryJobs::category($jobsData['category']))->rules('required', ['required' => '请选择职位小类'])->setMustMark();
  510. if (!empty($district)) {
  511. if (!isset($district[1])) {
  512. $district[1] = "";
  513. $district[2] = "";
  514. }//没有的话给默认值
  515. $form->select('province', '所属省份')->options(CategoryDistrict::List()->pluck('name', 'id'))->setWidth(3)->load('city', admin_base_path('sys/category/categoryDis'))->rules('required', ['required' => '请选择相应的企业所属省份'])->default($district[0])->setMustMark();
  516. $form->select('city', '所属城市')->options(CategoryDistrict::categoryDis($district[0]))->setWidth(3)->load('area', admin_base_path('sys/category/categoryDis'))->rules('required', ['required' => '请选择相应的企业所属城市'])->default($district[1])->setMustMark();
  517. //$form->select('area', '所属县区')->default(0)->setWidth(3)->setMustMark();
  518. } else {
  519. $form->select('province', '所属省份')->options(CategoryDistrict::List()->pluck('name', 'id'))->setWidth(3)->load('city', admin_base_path('sys/category/categoryDis'))->rules('required', ['required' => '请选择相应的企业所属省份'])->default(0)->setMustMark();
  520. $form->select('city', '所属城市')->setWidth(3)->load('area', admin_base_path('sys/category/categoryDis'))->rules('required', ['required' => '请选择相应的企业所属城市'])->default(0)->setMustMark();
  521. //$form->select('area', '所属县区')->setWidth(3)->default(0)->setMustMark();
  522. }
  523. // $form->select('syq', '试用期时间')->options(Category::categoryType('zs_syq'))->rules('required', array('required'=>'请选择试用期时间'))->setMustMark();
  524. // $form->number('syqxz_min', '试用期薪资')->min(config('aix.companyset.comset.com_set.wage_min'));
  525. if ($jobsData['wage'] == 0) {
  526. $form->hidden('wage');
  527. $form->number('wage_min', '最低薪资')->min(config('aix.companyset.comset.com_set.wage_min'))->help("请填写大于" . config('aix.companyset.comset.com_set.wage_min') . "的10的倍数");
  528. $form->number('wage_max', '最高薪资')->help("请填写大于最低薪资的10的倍数");
  529. } else {
  530. $option = Category::categoryType('AIX_wage');
  531. $option[-1] = '面议';
  532. $form->select('wage', '薪资待遇')->options($option)->default($jobsData['wage']);
  533. $form->hidden('wage_min');
  534. $form->hidden('wage_max');
  535. }
  536. $education = Category::categoryType('AIX_education');
  537. $education['0'] = '不限';
  538. $form->radio('education', '学历要求')->options($education);
  539. $experience = Category::categoryType('AIX_experience');
  540. $experience['0'] = "不限";
  541. $form->radio('experience', '工作经验')->options($experience);
  542. $form->radio('sex', '性别要求')->options([0 => '不限', 1 => '男', 2 => '女']);
  543. $form->radio('is_health', '卫健系统')->options([1 => '是', 2 => '否'])->default(2);
  544. $form->radio('health_type', '卫健招聘分类')->options([1 => '高层次人才', 2 => '紧缺急需', 3 => '统招', 4 => '编外'])->default(1);
  545. $form->radio('is_ic', '集成电路')->options([1 => '是', 2 => '否'])->default(2);
  546. $form->radio('is_deformity', '是否接受残疾人')->options([1 => '是', 2 => '否'])->default(2);
  547. $form->radio('is_soldier', '是否接受退役军人')->options([1 => '是', 2 => '否'])->default(2);
  548. $form->number('min_age', '最低年龄')->default(isset($jobsData['age'][0]) ? $jobsData['age'][0] : '')->min(16)->max(65)->help('最低年龄不能低于国家规定用工年龄');
  549. $form->number('max_age', '最高年龄')->default(isset($jobsData['age'][1]) ? $jobsData['age'][1] : '')->min(16)->max(65)->help('最高年龄不能高于65周岁');
  550. $form->number('amount', '招聘人数')->min(1)->max(99)->rules(['required'], ['required' => '请输入招聘人数'])->help('请填写招聘人数1~99')->setMustMark();
  551. $form->multipleSelect('tag', '职位亮点')->options(Category::categoryType('AIX_jobtag'));
  552. $form->textarea('jobs_content', '职位描述')->attribute(['maxlength' => 2000])->rules(['required'], ['required' => "请填写职位描述"])->setMustMark();
  553. })->tab('联系人', function (Form $form) {
  554. $form->text("contact.contact", '联系人')->setWidth(3);
  555. $form->radio('contact.contact_show', '联系人是否公开')->options([0 => '不公开', 1 => '公开']);
  556. $form->text('contact.telephone', '联系电话')->setWidth(3);
  557. $form->radio('contact.telephone_show', '联系电话是否公开')->options([0 => '不公开', 1 => '公开']);
  558. // $form->text('contact.landline_tel', '固定电话')->setWidth(3)->help('区号-号码-分机号(以“-”分隔)'); //这个字段引起问题
  559. // $form->radio('contact.landline_tel_show', '固定电话是否公开')->options([0=>'不公开',1=>'公开']);
  560. $form->text('contact.email', 'Email')->setWidth(3);
  561. $form->radio('contact.email_show', 'Email是否公开')->options([0 => '不公开', 1 => '公开']);
  562. $form->text('contact.address', '联系地址')->setWidth(3);
  563. });
  564. $form->disableEditingCheck();
  565. $form->disableCreatingCheck();
  566. $form->disableViewCheck();
  567. $form->disableReset();
  568. $form->tools(function ($tools) {
  569. $tools->disableView();
  570. $tools->disableDelete();
  571. });
  572. $form->ignore('province');
  573. $form->ignore('city');
  574. $form->ignore('area');
  575. $form->ignore('min_age');
  576. $form->ignore('max_age');
  577. $form->ignore(['relate_subsites']);
  578. $form->saving(function (Form $form) {
  579. $minage = Input::get('min_age');
  580. $maxage = Input::get('max_age');
  581. if ($maxage && $minage) {
  582. if ($maxage <= $minage) {
  583. $error = new MessageBag([
  584. 'title' => '提示',
  585. 'message' => '最高年龄不能小最低年龄',
  586. ]);
  587. return back()->with(compact('error'));
  588. }
  589. }
  590. if ($form->wage == -1) {
  591. $form->wage_min = 0;
  592. $form->wage_max = 0;
  593. } else {
  594. if ($form->wage != 0) {
  595. $wage = explode('~', format_wage(get_category($form->wage)));
  596. if (isset($wage[1])) {
  597. $form->wage_max = $wage[1];
  598. }
  599. $form->wage_min = $wage[0];
  600. } else {
  601. if ($form->wage_min < config('aix.companyset.comset.com_set.wage_min')) {
  602. $error = new MessageBag([
  603. 'title' => '提示',
  604. 'message' => '最低薪资请填写大于' . config('aix.companyset.comset.com_set.wage_min'),
  605. ]);
  606. return back()->with(compact('error'));
  607. }
  608. if ($form->wage_min % 10 != 0) {
  609. $error = new MessageBag([
  610. 'title' => '提示',
  611. 'message' => '薪资请填写10的倍数',
  612. ]);
  613. return back()->with(compact('error'));
  614. }
  615. if ($form->wage_max % 10 != 0) {
  616. $error = new MessageBag([
  617. 'title' => '提示',
  618. 'message' => '薪资请填写10的倍数',
  619. ]);
  620. return back()->with(compact('error'));
  621. }
  622. if (isset($form->wage_max) && $form->wage_max && $form->wage_max < $form->wage_min) {
  623. $error = new MessageBag([
  624. 'title' => '提示',
  625. 'message' => '最高薪资不能低于最低薪资',
  626. ]);
  627. return back()->with(compact('error'));
  628. }
  629. }
  630. }
  631. if (($form->min_age && !$form->max_age) || ($form->max_age && !$form->min_age)) {
  632. $error = new MessageBag([
  633. 'title' => '提示',
  634. 'message' => '请同时填写最高和最低年龄',
  635. ]);
  636. return back()->with(compact('error'));
  637. }
  638. if ($form->min_age && $form->min_age < 16) {
  639. $error = new MessageBag([
  640. 'title' => '提示',
  641. 'message' => '最低年龄不能小于16岁',
  642. ]);
  643. return back()->with(compact('error'));
  644. }
  645. if ($form->max_age && $form->min_age > 65) {
  646. $error = new MessageBag([
  647. 'title' => '提示',
  648. 'message' => '最高年龄不能大于65岁',
  649. ]);
  650. return back()->with(compact('error'));
  651. }
  652. if ($form->syqxz_min && $form->syqxz_min < $form->wage_min * 0.8) {
  653. $error = new MessageBag([
  654. 'title' => '提示',
  655. 'message' => '试用期薪资不得低于正式工资的80%',
  656. ]);
  657. return back()->with(compact('error'));
  658. }
  659. if ($form->syq == 367) {//无试用期 就把工资清0
  660. $form->syqxz_min = null;
  661. }
  662. });
  663. $form->saved(function (Form $form) use ($id) {
  664. $province = \Illuminate\Support\Facades\Request::input('province');
  665. $city = \Illuminate\Support\Facades\Request::input('city');
  666. $area = \Illuminate\Support\Facades\Request::input('area');
  667. $district = $province . '.' . $city . '.' . $area;
  668. $age[] = \Illuminate\Support\Facades\Request::input('min_age');
  669. $age[] = \Illuminate\Support\Facades\Request::input('max_age');
  670. $age = implode('-', $age);
  671. $jobsData = session('jobsData');//记录修改前的数据
  672. if (!empty($jobsData)) {
  673. if ($jobsData['audit'] != $form->model()->audit) {//修改了审核状态
  674. //审核日志$reason
  675. $auditData = [];
  676. $auditData['ids'] = $id;
  677. $auditData['status'] = $form->model()->audit;
  678. $auditData['type'] = 3;
  679. $auditData['reason'] = "";
  680. AuditReason::addData($auditData);
  681. }
  682. }
  683. Jobs::where('id', $id)->update(['district' => $district, 'age' => $age]);
  684. $subsites = \Illuminate\Support\Facades\Request::input('relate_subsites');
  685. if ($subsites) {
  686. $subsites = array_merge([get_subsite_id()], $subsites);
  687. SubsiteJob::where('jobs_id', $form->model()->id)->delete();
  688. $set_data = [];
  689. foreach ($subsites as $k => $v) {
  690. if ($v !== null) {
  691. $set_data[] = [
  692. 'jobs_id' => $form->model()->id,
  693. 'subsite_id' => $v,
  694. 'created_at' => date('Y-m-d H:i:s'),
  695. 'updated_at' => date('Y-m-d H:i:s'),
  696. ];
  697. }
  698. }
  699. SubsiteJob::insert($set_data);
  700. }
  701. });
  702. return $form;
  703. }
  704. public function update($id)
  705. {
  706. $result = $this->editForm($id)->update($id);
  707. event_search_update(Jobs::class, (string)$id, 'update');
  708. $cids = Jobs::where('id', $id)->pluck('company_id')->toArray();
  709. $company_condition = [['whereIn', 'id', $cids]];
  710. event_search_update(Company::class, $company_condition, 'update');
  711. return $result;
  712. }
  713. public function jobsAudit(Request $request)
  714. {
  715. $ids = $request->ids;
  716. if (!$ids) {
  717. return admin_toastr('请选择要审核的职位', 'error');
  718. }
  719. $id = explode(',', $ids);
  720. $job_com_ids = $this->jobsRepository->findWhereIn('id', $id, ['company_id', 'id', 'jobs_name'])->toArray();
  721. $reason = $request->reason;
  722. $audit = $request->audit1;
  723. $data = ['audit' => $audit];
  724. if (Jobs::jobsUpdate($id, $data)) {
  725. event_search_update(Jobs::class, implode(',', $id), 'update');
  726. if ($job_com_ids) {
  727. $company_ids = [];
  728. foreach ($company_ids as $k => $c) {
  729. $company_ids[] = $c['company_id'];
  730. }
  731. $company_condition = [['whereIn', 'id', $company_ids]];
  732. event_search_update(Company::class, $company_condition, 'update');
  733. }
  734. switch ($request->audit1) {
  735. case 1:
  736. $html = "通过审核";
  737. $alias = Smser::TEMPLATE_SMS_JOBSALLOW;
  738. break;
  739. case 3:
  740. $html = "未通过审核";
  741. $alias = Smser::TEMPLATE_SMS_JOBSNOTALLOW;
  742. break;
  743. }
  744. // if ($job_com_ids) {
  745. // $company_ids = [];
  746. // foreach ($job_com_ids as $k => $c) {
  747. // $company_ids[] = $c['company_id'];
  748. // $company = Company::find($c['company_id']);
  749. // $this->wechatService->sendTemplateMessage($company, 'set_jobsallow',[
  750. // 'keyword1'=>[$c['jobs_name'],'#0000ff'],
  751. // 'keyword2'=>[$html,$css],
  752. // 'keyword3'=>[$reason,'#0000ff'],
  753. // ],route('mobile.firm.jobs.list'));
  754. //
  755. // if($company->email){
  756. // $this->emailService->sendMail($company->email, $email, ['jobsname'=>$c['jobs_name']], ['jobsname'=>$c['jobs_name'],'sitedomain'=>route('com.index')]);
  757. // }
  758. //
  759. // }
  760. // $company_condition = [['whereIn','id', $company_ids]];
  761. // event_search_update(Company::class, $company_condition, 'update');
  762. // }
  763. $mobile = [];
  764. foreach ($id as $key => $val) {
  765. $jobsInfo = Jobs::with('jobsContact')->find($val);
  766. if ($jobsInfo->jobsContact && $jobsInfo->jobsContact->telephone) {
  767. if (!in_array($jobsInfo->jobsContact->telephone, $mobile)) {
  768. $mobile[] = $jobsInfo->jobsContact->telephone;
  769. $this->smsService->sendSms($jobsInfo->jobsContact->telephone, $alias, ['sitename' => config('aix.system.site.site.site_name'), 'jobsname' => $jobsInfo->jobs_name, 'sitedomain' => config('aix.system.site.site.site_domain')]);
  770. }
  771. }
  772. }
  773. //审核日志$reason
  774. $auditData = [];
  775. $auditData['ids'] = $id;
  776. $auditData['status'] = $audit;
  777. $auditData['type'] = 3;
  778. $auditData['reason'] = $reason;
  779. AuditReason::addData($auditData);
  780. if ($request->is_send) {
  781. // 站内信
  782. $insertData = [];
  783. foreach ($job_com_ids as $key => $val) {
  784. $insertData[$key] = [
  785. 'utype' => 1,
  786. 'msgtype' => 1,
  787. 'msgfromuid' => admin::user()->id,
  788. 'msgfrom' => admin::user()->username,
  789. 'msgtoname' => getComUserName($val['company_id']),
  790. 'msgtouid' => $val['company_id'],
  791. 'message' => '职位ID:' . $val['id'] . ',职位名称:' . $val['jobs_name'] . ',' . $html . ',【备注】' . $reason,
  792. 'new' => 1,
  793. 'created_at' => date('Y-m-d H:i:s', time()),
  794. 'updated_at' => date('Y-m-d H:i:s', time()),
  795. ];
  796. }
  797. $this->pmsService->addBatchPms($insertData);
  798. }
  799. if ($request->type) {
  800. admin_toastr('职位审核成功', 'success');
  801. return back();
  802. } else {
  803. return admin_toastr('职位审核成功', 'success');
  804. }
  805. } else {
  806. if ($request->type) {
  807. admin_toastr('职位审核失败', 'error');
  808. return back();
  809. } else {
  810. return admin_toastr('职位审核失败', 'error');
  811. }
  812. }
  813. }
  814. public function jobsbusiness(Content $content)
  815. {
  816. return $content->body(view(admin_base_path() . '/jobsbusiness/jobs_business'));
  817. }
  818. public function jobsrefresh(Request $request)
  819. {
  820. $ids = $request->ids;
  821. if (!$ids) {
  822. return admin_toastr('请选择要刷新的职位', 'error');
  823. }
  824. $id = explode(',', $ids);
  825. $data = ['refresh_time' => time()];
  826. if (Jobs::jobsUpdate($id, $data)) {
  827. event_search_update(Jobs::class, implode(',', $id), 'update');
  828. $com_ids = $this->jobsRepository->findWhereIn('id', $id, ['company_id'])->toArray();
  829. $company_condition = [['whereIn', 'id', $com_ids]];
  830. event_search_update(Company::class, $company_condition, 'update');
  831. return admin_toastr('职位刷新成功', 'success');
  832. } else {
  833. return admin_toastr('职位刷新失败', 'error!');
  834. }
  835. }
  836. //删除职位
  837. public function destroy($id)
  838. {
  839. $ids = explode(',', $id);
  840. $company_id = Jobs::select('company_id')->whereIn('id', $ids)->get()->toArray();
  841. $cids = [];
  842. if ($company_id) {
  843. foreach ($company_id as $k => $v) {
  844. $cids[] = $v['company_id'];
  845. }
  846. }
  847. DB::beginTransaction();//检查数据库事务
  848. try {
  849. if (false === Jobs::destroy($ids)) {
  850. throw new \Exception('删除职位失败!');
  851. }
  852. if (false === JobsContact::whereIn('job_id', $ids)->delete()) {
  853. throw new \Exception('职位联系人删除失败,删除职位失败!');
  854. }
  855. if (false === ViewJob::whereIn('job_id', $ids)->delete()) {
  856. throw new \Exception('职位被浏览信息删除失败,删除职位失败!');
  857. }
  858. $condition = [['whereIn', 'id', $ids]];
  859. event_search_update(Jobs::class, $condition, 'delete');
  860. $company_condition = [['whereIn', 'id', $cids]];
  861. event_search_update(Company::class, $company_condition, 'update');
  862. DB::commit();
  863. } catch (\Exception $e) {
  864. DB::rollback();
  865. return admin_toastr($e->getMessage(), 'error');
  866. }
  867. return admin_toastr('职位删除成功', 'success');
  868. }
  869. public function auditLog(Request $request)
  870. {
  871. $id = $request->id;
  872. $type = $request->type;
  873. $headers = ['status' => '审核状态', 'tim' => '审核时间', 'sec' => '描述'];
  874. $data = [];
  875. $res = AuditReason::where(['type_id' => $id, 'type' => $type])->orderBy('id', 'desc')->get();
  876. if (!$res) {
  877. $rows = $data;
  878. } else {
  879. foreach ($res as $k => $v) {
  880. if ($v['status'] == 3) {
  881. $data[$k]['status'] = '审核失败';
  882. } elseif ($v['status'] == 1) {
  883. $data[$k]['status'] = '审核通过';
  884. } else {
  885. $data[$k]['status'] = '待审核';
  886. }
  887. $data[$k]['tim'] = $v['created_at'];
  888. $data[$k]['sec'] = $v['audit_man'] . '--' . $v['reason'];
  889. }
  890. $rows = $data;
  891. }
  892. $table = new Table($headers, $rows);
  893. return ['html' => $table->render(), 'detail' => '审核日志'];
  894. }
  895. }