JobsController.php 41 KB

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