JobsService.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Api;
  12. use App\Models\JobsCategoryModel;
  13. use App\Models\JobsModel;
  14. use App\Services\BaseService;
  15. use App\Services\RedisService;
  16. use Illuminate\Support\Facades\DB;
  17. /**
  18. * 招聘管理-服务类
  19. * @author laravel开发员
  20. * @since 2020/11/11
  21. * @package App\Services\Api
  22. */
  23. class JobsService extends BaseService
  24. {
  25. /**
  26. * 构造函数
  27. * @author laravel开发员
  28. * @since 2020/11/11
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new JobsModel();
  33. }
  34. /**
  35. * 静态入口
  36. * @return static|null
  37. */
  38. public static function make()
  39. {
  40. if (!self::$instance) {
  41. self::$instance = (new static());
  42. }
  43. return self::$instance;
  44. }
  45. /**
  46. * @param $params
  47. * @param int $pageSize
  48. * @return array
  49. */
  50. public function getDataList($params, $pageSize = 15)
  51. {
  52. $where = ['a.mark' => 1];
  53. $status = isset($params['status']) ? $params['status'] : 0;
  54. $categoryId = isset($params['category_id']) ? $params['category_id'] : 0;
  55. if ($status > 0) {
  56. $where['a.status'] = $status;
  57. }
  58. if ($categoryId > 0) {
  59. $where['a.category_id'] = $categoryId;
  60. }
  61. $list = $this->model->with(['store','category'])->from('jobs as a')
  62. ->leftJoin('jobs_categorys as b', 'b.id', '=', 'a.category_id')
  63. ->where($where)
  64. ->where(function ($query) use ($params) {
  65. $keyword = isset($params['keyword']) ? $params['keyword'] : '';
  66. if ($keyword) {
  67. $query->where('a.job_name', 'like', "%{$keyword}%")
  68. ->orWhere('a.job_title','like',"%{$keyword}%")
  69. ->orWhere('a.tags','like',"%{$keyword}%")
  70. ->orWhere('a.company','like',"%{$keyword}%");
  71. }
  72. })
  73. ->select(['a.*'])
  74. ->orderBy('a.create_time', 'desc')
  75. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  76. $list = $list ? $list->toArray() : [];
  77. if ($list) {
  78. foreach ($list['data'] as &$item) {
  79. $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
  80. }
  81. }
  82. return [
  83. 'pageSize' => $pageSize,
  84. 'total' => isset($list['total']) ? $list['total'] : 0,
  85. 'list' => isset($list['data']) ? $list['data'] : []
  86. ];
  87. }
  88. /**
  89. * 分类
  90. * @return array|mixed
  91. */
  92. public function getCategoryList()
  93. {
  94. $cacheKey = "caches:jobs:categoryList";
  95. $datas = RedisService::get($cacheKey);
  96. if($datas){
  97. return $datas;
  98. }
  99. $datas = JobsCategoryModel::where(['pid'=>0,'status'=>1,'mark'=>1])
  100. ->select(['id','name','pid','remark','sort'])
  101. ->orderBy('sort','desc')
  102. ->orderBy('id','desc')
  103. ->get();
  104. $datas = $datas? $datas->toArray() : [];
  105. if($datas){
  106. RedisService::set($cacheKey, $datas, rand(300,600));
  107. }
  108. return $datas;
  109. }
  110. /**
  111. * 详情
  112. * @param $id
  113. * @param $userId
  114. * @return array|mixed
  115. */
  116. public function getInfo($id,$userId=0)
  117. {
  118. $cacheKey = "caches:jobs:info_{$id}_{$userId}";
  119. $info = RedisService::get($cacheKey);
  120. if($info){
  121. return $info;
  122. }
  123. $where = ['id'=> $id,'mark'=>1];
  124. $info = $this->model->with(['store','category'])->where($where)->first();
  125. $info = $info? $info->toArray() : [];
  126. if($info){
  127. $info['category_name'] = isset($info['category']) && $info['category']?$info['category']['name'] : '';
  128. RedisService::set($cacheKey, $info, rand(5, 10));
  129. }
  130. return $info;
  131. }
  132. }