JobfairoutCompanyController.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <?php
  2. namespace App\Admin\Controllers\Jobfairout;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Company;
  5. use App\Models\Subsite;
  6. use Encore\Admin\Controllers\HasResourceActions;
  7. use Encore\Admin\Facades\Admin;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Layout\Content;
  11. use Encore\Admin\Show;
  12. use App\Models\Jobfairout\JobfairoutCompany;
  13. use App\Models\Jobfairout\Jobfairout;
  14. use App\Models\Jobfairout\JobfairoutReserve;
  15. use App\Models\Jobfairout\JobfairoutPutJob;
  16. use App\Admin\Extensions\Form\ValidateForm;
  17. use Illuminate\Http\Request;
  18. use App\Services\Common\SmsService;
  19. use Aix\Sms\Contracts\Smser;
  20. use App\Services\Common\EmailService;
  21. use App\Models\MembersHandsel;
  22. use App\Models\MembersPoint;
  23. use App\Models\MembersSetmeal;
  24. use App\Models\Pms;
  25. class JobfairoutCompanyController extends Controller
  26. {
  27. use HasResourceActions;
  28. protected $smsService;
  29. protected $emailService;
  30. public function __construct(SmsService $smsService,EmailService $emailService)
  31. {
  32. $this->smsService = $smsService;
  33. $this->emailService = $emailService;
  34. }
  35. /**
  36. * Index interface.
  37. *
  38. * @param Content $content
  39. * @return Content
  40. */
  41. public function index(Content $content)
  42. {
  43. $grid=$this->grid()->render();
  44. return $content
  45. ->header('参会企业')
  46. ->description('')
  47. ->body(view('admin.jobfairout.jobfair_company')->with(['grid'=>$grid]));
  48. }
  49. /**
  50. * Show interface.
  51. *
  52. * @param mixed $id
  53. * @param Content $content
  54. * @return Content
  55. */
  56. public function show($id, Content $content)
  57. {
  58. return $content
  59. ->header('参会企业详情')
  60. ->description('')
  61. ->body($this->detail($id));
  62. }
  63. /**
  64. * Edit interface.
  65. *
  66. * @param mixed $id
  67. * @param Content $content
  68. * @return Content
  69. */
  70. public function edit($id, Content $content)
  71. {
  72. return $content
  73. ->header('参会企业编辑')
  74. ->description('')
  75. ->body($this->form()->edit($id));
  76. }
  77. /**
  78. * Create interface.
  79. *
  80. * @param Content $content
  81. * @return Content
  82. */
  83. public function create(Content $content)
  84. {
  85. return $content
  86. ->header('参会企业创建')
  87. ->description('带*号必填项')
  88. ->body($this->form());
  89. }
  90. /**
  91. * Make a grid builder.
  92. *
  93. * @return Grid
  94. */
  95. protected function grid()
  96. {
  97. $grid = new Grid(new JobfairoutCompany);
  98. $grid->model()->when(get_subsite_id()>0, function ($query) {
  99. $query->whereHas('jobfairout', function ($query) {
  100. $query->where('subsite_id', get_subsite_id());
  101. });
  102. })->orderByRaw("FIELD(audit, 2,1,3)")->orderBy('updated_at', 'desc');
  103. $grid->column('companys.companyname', '参会企业')->display(function ($companyname) {
  104. return '<a href="'.route('jobs.company',['id'=>$this->company_id]).'" target="_blank">'.$companyname.'</a>';
  105. })->width(200);
  106. $grid->person('参展人员信息')->display(function () {
  107. if($this->persons->isEmpty()){
  108. return '暂时没有';
  109. }else{
  110. return '<a href="'.route('jobfairout.company.person',['id'=>$this->id]).'" target="_blank">点击查看</a>';
  111. }
  112. });
  113. $grid->jobs_name('企业职位')->display(function () {
  114. if($this->jobfairPutJob->isEmpty()){
  115. return '暂无职位';
  116. }else{
  117. return '<a href="'.route('jobfairoutPutJobs.index',['jobfair_id'=>$this->jobfair_id,'company_id'=>$this->company_id]).'">点击查看</a>';
  118. }
  119. });
  120. $grid->column('jobfairout.title', '招聘会标题')->display(function ($jobfair_title) {
  121. return '<a href="'.route('jobfairout.show.com',$this->jobfair_id).'" target="_blank">'.$jobfair_title.'</a>';
  122. })->width(200);
  123. $grid->column('info.is_speech', '是否演讲')->display(function ($is_speech) {
  124. if($is_speech ==1)
  125. {
  126. return ' <span style="color: #009900">是</span>';
  127. }else{
  128. return ' <span style="color: #FF3300">否</span>';
  129. }
  130. });
  131. $grid->audit('预订状态')->display(function ($audit) {
  132. if ($audit==1) {
  133. return ' <span style="color: #009900">预定成功</span>';
  134. } elseif ($audit==2) {
  135. return'<span style="color:#FF6600">等待确认</span>';
  136. } else {
  137. return '<span style="color: #FF3300">审核未通过</span>';
  138. }
  139. });
  140. $grid->pay_type('支付方式')->display(function ($pay_type) {
  141. if ($pay_type==1) {
  142. return '<span style="color: #009900">场次</span>';
  143. } elseif ($pay_type==2) {
  144. return '<span style="color: #009900">积分</span>';
  145. } else {
  146. return '<span style="color: #009900">公益</span>';
  147. }
  148. });
  149. $grid->etype('预订方式')->display(function ($etype) {
  150. if ($etype==1) {
  151. return '<span style="color: #009900">在线预订</span>';
  152. } elseif ($etype==2) {
  153. return '<span style="color: #009900">电话预定</span>';
  154. } else {
  155. return '<span style="color: #009900">现场预定</span>';
  156. }
  157. });
  158. if(get_subsite_open()){
  159. $grid->column('jobfairout.subsite_id', '所属分站')->display(function ($subsite_id) {
  160. if ($subsite_id) {
  161. $Subsite = Subsite::find($subsite_id);
  162. return isset($Subsite->sitename) ? $Subsite->sitename : '未知';
  163. }
  164. return '总站';
  165. });
  166. }
  167. $grid->created_at('创建时间');
  168. /* $grid->disableCreateButton();*/
  169. $grid->actions(function ($actions) use ($grid) {
  170. if (Admin::user()->can('company_manager_bussiness')) {
  171. $actions->append("<button class='btn btn-primary btn-xs business' id=".$actions->row['company_id'].">业务</button>");
  172. }
  173. if (Admin::user()->can('jobfairout_company_audit')) {
  174. $actions->append("<button class='btn btn-primary btn-xs jobaudit' data-code=".$actions->row['id'].">审核</button>");
  175. }
  176. if (Admin::user()->can('jobfairout_companys_edit')) {
  177. $actions->disableEdit(false);
  178. }
  179. if (Admin::user()->can('jobfairout_companys_delete')) {
  180. $actions->disableDelete(false);
  181. }
  182. if (Admin::user()->can('jobfairout_company_poster')) {
  183. $actions->append('<button class="btn btn-primary btn-xs poster" title="企业海报" onclick="window.open(\''.route('jobfairout.company.poster',['id'=>$actions->row['id']]).'\')" >企业海报</button>');
  184. }
  185. });
  186. if (Admin::user()->can('jobfairout_company_delete')) {
  187. $grid->tools(function ($tools) {
  188. $tools->batch(function ($batch) {
  189. $batch->disableDelete(false);
  190. });
  191. });
  192. $grid->disableRowSelector(false);
  193. }
  194. if (Admin::user()->can('jobfairout_companys_create')) {
  195. $grid->disableCreateButton(false);
  196. }
  197. $grid->tools(function ($tools) {
  198. if (Admin::user()->can('jobfairout_company_audit')) {
  199. $but = <<<EOT
  200. <div class="btn-group" data-toggle="buttons">
  201. <label class="btn btn-google btn-sm" id="Audit_Companys" title="参会状态">
  202. <i class="fa fa-audio-description"></i>
  203. <input type="radio" class="user-gender">审核企业
  204. </label>
  205. </div>
  206. EOT;
  207. $tools->append($but);
  208. }
  209. });
  210. $grid->filter(function ($filter) {
  211. // 去掉默认的id过滤器
  212. $filter->disableIdFilter();
  213. $filter->column(1/2, function ($filter) {
  214. $filter->like('companys.companyname', '参会企业');
  215. $filter->equal('jobfair_companys.jobfair_id', '招聘会标题')->select(Jobfairout::select('title', 'id')->when(get_subsite_id()>0,function ($query){
  216. $query->whereHas('subsites', function ($query) {
  217. $query->where('subsite_jobfairouts.subsite_id', get_subsite_id())->where('subsites.effective', 1);
  218. });
  219. })->pluck('title', 'id')->all());
  220. $filter->equal('jobfair_companys.audit', '预订状态')->select([
  221. 1=>'预定成功',
  222. 2=>'等待确认',
  223. 3=>'审核未通过',
  224. ]);
  225. if( get_subsite_id() == 0 && get_subsite_open()){
  226. $filter->equal('jobfairout.subsite_id', '所属分站')->select(array_column(get_all_subsite(), 'sitename', 'id'));
  227. }
  228. });
  229. $filter->column(1/2, function ($filter) {
  230. $filter->equal('jobfair_companys.pay_type', '支付方式')->select([
  231. 1=>'场次',
  232. 2=>'积分',
  233. 3=>'公益',
  234. ]);
  235. $filter->equal('jobfair_companys.etype', '预订方式')->select([
  236. 1=>'在线预订',
  237. 2=>'电话预定',
  238. 3=>'现场预定'
  239. ]);
  240. $filter->where(function ($query) {
  241. switch ($this->input) {
  242. case 3:
  243. $query->whereRaw("jobfair_companys.updated_at>='".date('Y-m-d H:i:s', strtotime('-3 day'))."'");
  244. break;
  245. case 7:
  246. $query->whereRaw("jobfair_companys.updated_at>='".date('Y-m-d H:i:s', strtotime('-7 day'))."'");
  247. break;
  248. case 30:
  249. $query->whereRaw("jobfair_companys.updated_at>='".date('Y-m-d H:i:s', strtotime('-30 day'))."'");
  250. break;
  251. }
  252. }, '更新时间', 'updated_at')->select([
  253. 3=>'三天内',
  254. 7=>'一周内',
  255. 30=>'一月内',
  256. ]);
  257. });
  258. });
  259. return $grid;
  260. }
  261. /**
  262. * Make a show builder.
  263. *
  264. * @param mixed $id
  265. * @return Show
  266. */
  267. protected function detail($id)
  268. {
  269. $show = new Show(JobfairoutCompany::findOrFail($id));
  270. $jobfairCompany = JobfairoutCompany::findOrFail($id);
  271. $show->id('ID');
  272. $show->companys()->companyname('参会企业')->as(function ($companys){
  273. return $companys->companyname;
  274. });
  275. $show->jobfairout()->title('招聘会标题')->as(function ($jobfair){
  276. return $jobfair->title;
  277. });
  278. $show->type('签到状态')->as(function ($type) {
  279. if ($type==0) {
  280. return '未签到';
  281. } elseif ($type==1) {
  282. return '迟到';
  283. } elseif ($type==2) {
  284. return '早退';
  285. } elseif ($type==3) {
  286. return '迟到/早退';
  287. } elseif ($type==4) {
  288. return '已签到';
  289. }
  290. });
  291. $show->audit('预订状态')->as(function ($audit) {
  292. if ($audit==1) {
  293. return '预定成功';
  294. } elseif ($audit==2) {
  295. return '等待确认';
  296. } else {
  297. return '审核未通过';
  298. }
  299. });
  300. $show->pay_type('支付方式')->as(function ($pay_type) {
  301. if ($pay_type==1) {
  302. return '场次';
  303. } elseif ($pay_type==2) {
  304. return '积分';
  305. } else {
  306. return '公益';
  307. }
  308. });
  309. $show->etype('预订方式')->as(function ($etype) {
  310. if ($etype==1) {
  311. return '在线预订';
  312. } elseif ($etype==2) {
  313. return '电话预定';
  314. } else {
  315. return '现场预定';
  316. }
  317. });
  318. $show->subsite_id('所属分站')->as(function () use ($jobfairCompany) {
  319. $subsite_id = Jobfairout::findOrFail($jobfairCompany->jobfair_id)->subsite_id;
  320. if ($subsite_id) {
  321. $Subsite = Subsite::find($subsite_id);
  322. return isset($Subsite->sitename) ? $Subsite->sitename : '未知';
  323. }
  324. return '总站';
  325. });
  326. $show->created_at('创建时间');
  327. $show->updated_at('更新时间');
  328. return $show;
  329. }
  330. /**
  331. * Make a form builder.
  332. *
  333. * @return Form
  334. */
  335. protected function form()
  336. {
  337. $form = new ValidateForm(new JobfairoutCompany);
  338. $form->select('company_id', '企业名称')->options(
  339. Company::pluck('companyname', 'id')->all()
  340. )->rules([
  341. 'required',
  342. ])->setMustMark();
  343. $form->select('jobfair_id', '招聘会名称')->options(
  344. Jobfairout::where('display', 1)->where('predetermined_status',1)->where('holddate_end', '>', time())->pluck('title', 'id')->all()
  345. )->rules(['required',])->setMustMark();
  346. $form->select('etype', '预定方式')->options([3=>'现场预定'])->default(3)->help('现场预定不消耗场次或积分!');
  347. $form->hidden('pay_type')->default(3);
  348. $form->saving(function (Form $form){
  349. $company_id = $form->company_id;
  350. $count = JobfairoutCompany::where(['company_id'=>$company_id,'jobfair_id'=>$form->jobfair_id])->count();
  351. if ($count>=1) {
  352. admin_toastr('该企业已预定过该招聘会!', 'error');
  353. return back();
  354. }
  355. });
  356. $form->saved(function (Form $form) {
  357. $model = $form->model();
  358. $model->audit = 1;
  359. $model->note = '该企业现场预定展位!';
  360. $model->save();
  361. });
  362. return $form;
  363. }
  364. public function person(Request $request)
  365. {
  366. $id = $request->id;
  367. $reserve = JobfairoutReserve::where('exid',$id)->get();
  368. return view('admin.jobfairout.jobfair_company_person',['reserve'=>$reserve]);
  369. }
  370. public function poster(Request $request)
  371. {
  372. $id = $request->id;
  373. $poster = JobfairoutCompany::find($id);
  374. return view('admin.jobfairout.jobfair_company_poster',['poster'=>$poster]);
  375. }
  376. public function auditCompanys(Request $request)
  377. {
  378. $id = $request->id;
  379. $form = new \Encore\Admin\Widgets\Form();
  380. $form->action(route('jobfairout.company.auditr'));
  381. $form->disableReset();
  382. $form->hidden('id', 'ID')->default($id);
  383. $form->radio('audit', '审核')->options([1=>'预订成功',3=>'审核未通过'])->default(1);
  384. $form->textarea('note', '备注');
  385. $form->html('<label style="color: rgb(0, 153, 0)"><input type="checkbox" name="pms_notice" value="1" checked="checked">站内信通知</label>');
  386. return json_encode(['html'=>$form->render(),'detail'=>'审核企业']);
  387. }
  388. public function auditCompanysR(Request $request)
  389. {
  390. $id = $request->id;
  391. $audit = $request->audit;
  392. $note = $request->note;
  393. $pms_notice = $request->pms_notice;
  394. if($audit==3){
  395. if (empty($note)) {
  396. admin_toastr('参会企业审核未通过必须填写备注!', 'error');
  397. return back();
  398. }
  399. }
  400. $arr = array_filter(explode(',', $id));
  401. if (empty($arr)) {
  402. admin_toastr('请选择参会企业', 'error');
  403. return back();
  404. }
  405. $arr_id = [];
  406. $JobfairCompany = JobfairoutCompany::whereHas('jobfairout',function ($query){
  407. $query->where('holddate_end', '>', time());
  408. })->whereIn('id', $arr)->get();
  409. if($JobfairCompany->isEmpty()){
  410. admin_toastr('招聘会已过期', 'error');
  411. return back();
  412. }
  413. \DB::beginTransaction();
  414. try {
  415. foreach ($JobfairCompany as $key => $val) {
  416. if ($audit==1) { //预订成功
  417. if ($val->audit==2) {
  418. $arr_id[] = $val->id;
  419. if($val->companys->mobile && $val->companys->mobile_audit == 1){
  420. $this->smsService->sendSms(
  421. $val->companys->mobile,
  422. Smser::TEMPLATE_JOBFAIR_APPLY_OK,
  423. [
  424. 'jobfair_name'=>$val->jobfairout->title,
  425. 'jobfair_time'=>date('Y-m-d H:i',$val->jobfairout->holddate_start),
  426. 'jobfair_addr'=>$val->jobfairout->address,
  427. ]);
  428. }
  429. if($val->companys->email && $val->companys->email_audit == 1){
  430. $this->emailService->sendMail($val->companys->email, EmailService::TEMPLATE_JOBFAIR_APPLY_OK,
  431. ['title'=>'赴外招聘会预订成功'],
  432. [
  433. 'jobfair_name'=>$val->jobfairout->title,
  434. 'jobfair_time'=>date('Y-m-d H:i',$val->jobfairout->holddate_start),
  435. 'jobfair_addr'=>$val->jobfairout->address,
  436. ]
  437. );
  438. }
  439. }
  440. } else { //审核未通过。
  441. if ($val->audit==2 || $val->audit==1) {
  442. $arr_id[] = $val->id;
  443. if($val->companys->mobile && $val->companys->mobile_audit == 1){
  444. $this->smsService->sendSms(
  445. $val->companys->mobile,
  446. Smser::TEMPLATE_JOBFAIR_APPLY_ERROR,
  447. [
  448. 'jobfair_name'=>$val->jobfairout->title
  449. ]);
  450. }
  451. if($val->companys->email && $val->companys->email_audit == 1){
  452. $this->emailService->sendMail($val->companys->email, EmailService::TEMPLATE_JOBFAIR_APPLY_ERROR, ['title'=>'赴外招聘会预订失败'], ['jobfair_name'=>$val->jobfairout->title]);
  453. }
  454. }
  455. if ($val->jobfairout) {
  456. if ($val->pay_type==1) {//场次
  457. MembersSetmeal::where('uid', $val->company_id)->where('utype', 1)
  458. ->increment('jobfair_num', $val->jobfairout->jobsfair_num);
  459. }elseif ($val->pay_type==2) { //积分
  460. MembersPoint::where('uid', $val->company_id)->where('utype', 1)
  461. ->increment('points', $val->jobfairout->predetermined_point);
  462. MembersHandsel::create([
  463. 'uid'=>$val->company_id,
  464. 'utype'=>1,
  465. 'htype_cn'=>'返还预定招聘会的积分',
  466. 'operate'=>1,
  467. 'points'=>$val->jobfairout->predetermined_point
  468. ]);
  469. }
  470. }
  471. }
  472. }
  473. if ($arr_id) {
  474. $newReult = JobfairoutCompany::with(['jobfairout', 'companys'])->whereHas('jobfairout')
  475. ->whereHas('companys')->whereIn('id', $arr_id)->get();
  476. foreach ($newReult as $key => $val) {
  477. if ($val->jobfairout && $val->companys) {
  478. $newDate[$key]['utype'] = $val->companys->utype;
  479. $newDate[$key]['msgtype'] = 2;
  480. $newDate[$key]['msgfromuid'] = 0;
  481. $newDate[$key]['msgfrom'] = 'admin';
  482. $newDate[$key]['msgtoname'] = $val->companys->username;
  483. $newDate[$key]['msgtouid'] = $val->companys->id;
  484. $title = strstr($val->jobfairout->title, '赴外—招聘会') ? $val->jobfairout->title : $val->jobfairout->title . '赴外—招聘会';
  485. if ($audit == 1) {
  486. $newDate[$key]['message'] = '您申请的<a href="/content/jobfairout/show/' . $val->jobfairout->id . '">' . $title . '</a>已审核通过,请尽快提交招聘会职位。';
  487. } else {
  488. $newDate[$key]['message'] = '您申请的<a href="/content/jobfairout/show/' . $val->jobfairout->id . '">' . $title . '</a>已审核失败,请尽快查收。失败原因(' . $note . ')';
  489. }
  490. $newDate[$key]['created_at'] = date('Y-m-d H:i:s');
  491. $newDate[$key]['updated_at'] = date('Y-m-d H:i:s');
  492. }
  493. }
  494. if ($pms_notice&&$newDate) {
  495. Pms::insert($newDate);
  496. }
  497. JobfairoutCompany::whereIn('id', $arr_id)->update(['audit' => $audit, 'note' => $note]);
  498. } else {
  499. admin_toastr('操作失败', 'error');
  500. return back();
  501. }
  502. \DB::commit();
  503. admin_toastr('操作成功', 'success');
  504. } catch (\Exception $e) {
  505. \DB::rollback();
  506. admin_toastr('操作失败', $e->getMessage());
  507. }
  508. return back();
  509. }
  510. public function destroy($id)
  511. {
  512. $ids = array();
  513. if ($id) {
  514. $ids = explode(',', $id);
  515. }
  516. if (!$ids) {
  517. return admin_toastr('请勾选需要删除的参展职位', 'error');
  518. }
  519. \DB::beginTransaction();
  520. try {
  521. JobfairoutCompany::whereIn('id', $ids)->delete();
  522. JobfairoutPutJob::whereIn('exid', $ids)->delete();
  523. $data = [
  524. 'status' => true,
  525. 'message' => trans('admin.delete_succeeded'),
  526. ];
  527. \DB::commit();
  528. return response()->json($data);
  529. } catch (\Exception $e) {
  530. \DB::rollback();
  531. $data = [
  532. 'status' => false,
  533. 'message' => trans('admin.delete_failed'),
  534. ];
  535. return response()->json($data);
  536. }
  537. }
  538. }