JobsController.php 42 KB

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