JobfairoutService.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: ZhangHao
  5. * Date: 2019/6/17
  6. * Time: 11:11
  7. */
  8. namespace App\Services\Jobfairout;
  9. use App\Models\Subsite;
  10. use App\Repositories\Jobfairout\JobfairoutRepository;
  11. use App\Repositories\Jobfairout\JobfairoutCompanyRepository;
  12. use App\Repositories\Jobfairout\jobfairoutPutJobRepository;
  13. use App\Repositories\Jobfairout\jobfairoutSchoolRepository;
  14. use App\Repositories\MemberSetmealRepository;
  15. use App\Repositories\MemberPointRepository;
  16. use App\Services\Jobfair\JobfairService;
  17. use Illuminate\Support\Facades\DB;
  18. class JobfairoutService
  19. {
  20. protected $jobfairoutRepository;
  21. protected $jobfairoutCompanyRepository;
  22. protected $jobfairoutPutJobRepository;
  23. protected $memberSetmealRepository;
  24. protected $memberPointRepository;
  25. protected $jobfairoutSchoolRepository;
  26. protected $jobfairService;
  27. public function __construct(
  28. JobfairoutRepository $jobfairoutRepository,
  29. JobfairoutCompanyRepository $jobfairoutCompanyRepository,
  30. jobfairoutPutJobRepository $jobfairoutPutJobRepository,
  31. MemberSetmealRepository $memberSetmealRepository,
  32. MemberPointRepository $memberPointRepository,
  33. jobfairoutSchoolRepository $jobfairoutSchoolRepository,
  34. JobfairService $jobfairService
  35. )
  36. {
  37. $this->jobfairoutRepository = $jobfairoutRepository;
  38. $this->jobfairoutCompanyRepository = $jobfairoutCompanyRepository;
  39. $this->jobfairoutPutJobRepository = $jobfairoutPutJobRepository;
  40. $this->memberSetmealRepository = $memberSetmealRepository;
  41. $this->memberPointRepository = $memberPointRepository;
  42. $this->jobfairoutSchoolRepository = $jobfairoutSchoolRepository;
  43. $this->jobfairService = $jobfairService;
  44. }
  45. /**近期招聘会
  46. * @return array
  47. */
  48. public function jobfairIndex($user)
  49. {
  50. $jobfairList = $this->jobfairoutRepository->getJobfairList($user->id);
  51. foreach ($jobfairList as $key => $val) {
  52. $val->predetermined_ok = 0;
  53. if ($val->predetermined_status == 1 && $val->predetermined_start && $val->predetermined_start < time() && $val->predetermined_end && $val->predetermined_end > time()) {
  54. $val->predetermined_ok = 1;
  55. }
  56. }
  57. $week = ['日','一','二','三','四','五','六'];
  58. return [
  59. 'jobfairList'=>$jobfairList,
  60. 'week'=>$week,
  61. ];
  62. }
  63. /**招聘会详情
  64. * @param $id
  65. * @return array
  66. */
  67. public function jobfairShow($id,$user)
  68. {
  69. $map1 =['id'=>$id];
  70. $jobfair = $this->jobfairoutRepository->findOne($map1);
  71. if (!$jobfair) {
  72. return ['status'=>0, 'msg'=>'查无此招聘会'];
  73. }
  74. if ($jobfair->predetermined_status == 1 && $jobfair->predetermined_start && $jobfair->predetermined_start < time() && $jobfair->predetermined_end && $jobfair->predetermined_end > time()) {
  75. $jobfair->predetermined_ok =1;
  76. } else {
  77. $jobfair->predetermined_ok =0;
  78. }
  79. $jobfair->phone_html = '';
  80. if($jobfair->phone){
  81. foreach (explode(',',$jobfair->phone) as $value){
  82. $jobfair->phone_html .= '<a href="tel:'.$value.'" style=" text-decoration: none;color: #0180CF; ">'.$value .'</a><br/><br/>';
  83. }
  84. }
  85. //空余展位数
  86. $map = [
  87. 'jobfair_id'=>$id, ['audit','<>',3]
  88. ];
  89. $companyCount = $this->jobfairoutCompanyRepository->getComCount($map);
  90. $jobfair->countSurplus = $jobfair->number - $companyCount;
  91. //判断是否预定过
  92. if($user){
  93. $jobfair->is_appointment = $this->jobfairoutCompanyRepository->jobfairAppointment(['jobfair_id'=>$id,['audit','<>',3],'company_id'=>$user->id]);
  94. }else{
  95. $jobfair->is_appointment = false;
  96. }
  97. //学校列表
  98. $schools = [];
  99. if($jobfair->school_id){
  100. $schools = $this->jobfairoutSchoolRepository->getSchool(explode(',',$jobfair->school_id));
  101. }
  102. return [
  103. 'status'=>1,
  104. 'jobfair'=>$jobfair,
  105. 'schools'=>$schools,
  106. ];
  107. }
  108. /**招聘会企业
  109. * @param $request
  110. * @param $id
  111. * @return array
  112. */
  113. public function jobfairShowCom($request, $id,$user)
  114. {
  115. $jobfair = $this->jobfairoutRepository->findJobfair(['id'=>$id]);
  116. if (!$jobfair) {
  117. return ['status'=>0, 'msg'=>'查无此招聘会'];
  118. }
  119. $map = [
  120. 'jobfair_id'=>$id, ['audit','<>',3]
  121. ];
  122. $companyCount = $this->jobfairoutCompanyRepository->getComCount($map);
  123. $jobfair->countSurplus = $jobfair->number - $companyCount;
  124. if ($jobfair->predetermined_status == 1 && $jobfair->predetermined_start && $jobfair->predetermined_start < time() && $jobfair->predetermined_end && $jobfair->predetermined_end > time()) {
  125. $jobfair->predetermined_ok =1;
  126. } else {
  127. $jobfair->predetermined_ok =0;
  128. }
  129. //判断是否预定过
  130. if($user){
  131. $jobfair->is_appointment = $this->jobfairoutCompanyRepository->jobfairAppointment(['jobfair_id'=>$id,['audit','<>',3],'company_id'=>$user->id]);
  132. }else{
  133. $jobfair->is_appointment = false;
  134. }
  135. $where = ['jobfair_id'=>$id,'audit'=>1];
  136. $offset = isset($request->page)?$request->page:0;
  137. $limit = 20;
  138. $jobfairCompany = $this->jobfairoutCompanyRepository->findCompany($where, $offset, $limit);
  139. foreach ($jobfairCompany as $key => $val) {
  140. $where = [
  141. 'jobfair_id'=>$id,
  142. 'company_id'=>$val->company_id,
  143. ];
  144. $val->jobfairPutJob = $this->jobfairoutPutJobRepository->getJobfairJob($where);
  145. }
  146. if ($request->ajax()) {
  147. return $jobfairCompany;
  148. }
  149. $more = count($jobfairCompany) >= $limit ? true : false;
  150. $jobsSum = $this->jobfairoutPutJobRepository->getNeedPerson($id);
  151. $needPersonCount = isset($jobsSum['sum']) ? $jobsSum['sum'] : 0;
  152. //学校列表
  153. $schools = [];
  154. if($jobfair->school_id){
  155. $schools = $this->jobfairoutSchoolRepository->getSchool(explode(',',$jobfair->school_id));
  156. }
  157. return [
  158. 'status'=>1,
  159. 'jobfair'=>$jobfair,
  160. 'jobfairCompany'=>$jobfairCompany,
  161. 'companyCount'=>$companyCount,
  162. 'more'=>$more,
  163. 'schools'=>$schools,
  164. 'needPersonCount'=>$needPersonCount,
  165. ];
  166. }
  167. public function jobfairAppointmentSave($jobfairInfo, $user)
  168. {
  169. //允许预订 举办开始日期大于当前日期 预订结束时间大于当前时间 允许在线预订
  170. if ($jobfairInfo->predetermined_status == 2) {
  171. return response()->json(['status'=>0, 'msg'=>"很抱歉,招聘会已停止预定"]);
  172. }
  173. if (time() > $jobfairInfo->holddate_end) {
  174. return response()->json(['status'=>0, 'msg'=>"很抱歉,招聘会已结束"]);
  175. }
  176. if ($jobfairInfo->is_commonweal == 1) {
  177. $num = $jobfairInfo->jobsfair_num;
  178. $mySetmeal = $this->memberSetmealRepository->getSetmealByUid($user->id, 1);
  179. if ($mySetmeal->jobfair_num < $num) {
  180. return response()->json(['status' => 0, 'msg' => "很抱歉,您的会员招聘会场次不足。请先升级套餐!"]);
  181. }
  182. }
  183. if ($jobfairInfo->is_commonweal == 2) {
  184. $num = $jobfairInfo->predetermined_point;
  185. $myPoints = $this->memberPointRepository->getComPointsById($user->id, 1);
  186. if ($myPoints->points < $num) {
  187. return response()->json(['status' => 0, 'msg' => "很抱歉,您的会员积分不足。请先积分充值!"]);
  188. }
  189. }
  190. $insertData['company_id'] = $user->id;
  191. $insertData['jobfair_id'] = $jobfairInfo->id;
  192. $insertData['pay_type'] = $jobfairInfo->is_commonweal;
  193. DB::beginTransaction();
  194. try {
  195. if (!$this->jobfairoutCompanyRepository->create($insertData)) {
  196. throw new \Exception('招聘会预定失败!');
  197. }
  198. if ($jobfairInfo->is_commonweal != 3) {
  199. $res = $this->jobfairService->payType($jobfairInfo->is_commonweal, $num, $user);
  200. if (!$res['status']) {
  201. throw new \Exception($res['msg']);
  202. }
  203. }
  204. DB::commit();
  205. return response()->json(['status'=>1, 'msg'=>"注意:恭喜您,预定成功,请到定展记录里填写 <span style='color:#FC4C4E;'> 单位信息、职位信息、参会人</span>",'data'=>['companyname'=>$user->companyname]]);
  206. } catch (\Exception $e) {
  207. DB::rollback();
  208. return response()->json(['status'=>0, 'msg'=>$e->getMessage()]);
  209. }
  210. }
  211. /**职位详情
  212. * @param $jobfair_id
  213. * @param $job_id
  214. * @return array
  215. */
  216. public function jobfairShowJob($id)
  217. {
  218. $jobInfo = $this->jobfairoutPutJobRepository->getOne(['id'=>$id]);
  219. if (!$jobInfo) {
  220. return ['status'=>0, 'msg'=>'查无此职位!'];
  221. }
  222. if ($jobInfo->jobfairs->holddate_end > time()) {
  223. $jobInfo->jobs->predetermined_ok = 1;
  224. } else {
  225. $jobInfo->jobs->predetermined_ok = 0;
  226. }
  227. if ($jobInfo->jobs->subclass) {
  228. $jobInfo->jobs->category_cn = get_job_category($jobInfo->jobs->subclass);
  229. }
  230. if ($jobInfo->jobs->tag_cn) {
  231. $jobInfo->jobs->tag_cn = explode(',',$jobInfo->jobs->tag_cn);
  232. }
  233. return [
  234. 'status'=>1,
  235. 'jobInfo'=>$jobInfo,
  236. ];
  237. }
  238. public function getJobfairOpen()
  239. {
  240. $jonfair_id = [];
  241. $jobfair = $this->jobfairoutRepository->getJobfairOpen();
  242. foreach ($jobfair as $key => $val) {
  243. if ($val->predetermined_start) {
  244. if ($val->predetermined_start>time()||$val->predetermined_end<time()) {
  245. $jonfair_id[] = $val->id;
  246. }
  247. } else {
  248. if ($val->holddate_start<time()) {
  249. $jonfair_id[] = $val->id;
  250. }
  251. }
  252. }
  253. return $jonfair_id;
  254. }
  255. }