JobsService.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. if ($status > 0) {
  55. $where['a.status'] = $status;
  56. }
  57. $list = $this->model->with(['store','category'])->from('jobs as a')
  58. ->leftJoin('jobs_categorys as b', 'b.id', '=', 'a.category_id')
  59. ->where($where)
  60. ->where(function ($query) use ($params) {
  61. $keyword = isset($params['keyword']) ? $params['keyword'] : '';
  62. if ($keyword) {
  63. $query->where('a.job_name', 'like', "%{$keyword}%")
  64. ->orWhere('a.job_title','like',"%{$keyword}%")
  65. ->orWhere('a.tags','like',"%{$keyword}%")
  66. ->orWhere('a.company','like',"%{$keyword}%");
  67. }
  68. })
  69. ->select(['a.*'])
  70. ->orderBy('a.create_time', 'desc')
  71. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  72. $list = $list ? $list->toArray() : [];
  73. if ($list) {
  74. foreach ($list['data'] as &$item) {
  75. $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
  76. }
  77. }
  78. return [
  79. 'pageSize' => $pageSize,
  80. 'total' => isset($list['total']) ? $list['total'] : 0,
  81. 'list' => isset($list['data']) ? $list['data'] : []
  82. ];
  83. }
  84. /**
  85. * 分类
  86. * @return array|mixed
  87. */
  88. public function getCategoryList()
  89. {
  90. $cacheKey = "caches:jobs:categoryList";
  91. $datas = RedisService::get($cacheKey);
  92. if($datas){
  93. return $datas;
  94. }
  95. $datas = JobsCategoryModel::where(['pid'=>0,'status'=>1,'mark'=>1])
  96. ->select(['id','name','pid','remark','sort'])
  97. ->orderBy('sort','desc')
  98. ->orderBy('id','desc')
  99. ->get();
  100. $datas = $datas? $datas->toArray() : [];
  101. if($datas){
  102. RedisService::set($cacheKey, $datas, rand(300,600));
  103. }
  104. return $datas;
  105. }
  106. /**
  107. * 申请
  108. * @param $userId
  109. * @param $params
  110. * @return mixed
  111. */
  112. public function apply($userId, $params)
  113. {
  114. $name = isset($params['name']) ? trim($params['name']) : '';
  115. $realname = isset($params['real_name']) ? trim($params['real_name']) : '';
  116. $phone = isset($params['phone']) ? trim($params['phone']) : '';
  117. $address = isset($params['address']) ? trim($params['address']) : '';
  118. $categoryId = isset($params['category_id']) ? intval($params['category_id']) : 0;
  119. $logo = isset($params['logo']) && $params['logo']? get_image_path($params['logo']) : '';
  120. $businessLicense = isset($params['business_license']) && $params['business_license']? get_image_path($params['business_license']) : '';
  121. $otherPhoto = isset($params['other_photo']) && $params['other_photo']? get_image_path($params['other_photo']) : '';
  122. $data = [
  123. 'user_id' => $userId,
  124. 'name' => $name,
  125. 'real_name' => $realname,
  126. 'phone' => $phone,
  127. 'address' => $address,
  128. 'category_id' => $categoryId,
  129. 'logo' => $logo,
  130. 'business_license' => $businessLicense,
  131. 'other_photo' => $otherPhoto,
  132. 'order_count' => 0,
  133. 'order_total' => 0,
  134. 'confirm_remark' => '',
  135. 'create_time' => time(),
  136. 'update_time' => time(),
  137. 'status' => 2,
  138. 'mark' => 1,
  139. ];
  140. DB::beginTransaction();
  141. if($id = $this->model->where(['user_id'=>$userId])->value('id')){
  142. $this->model->where(['id'=>$id])->update($data);
  143. }else{
  144. if (!$id = $this->model->insertGetId($data)) {
  145. DB::rollBack();
  146. $this->error = '申请入驻失败';
  147. return false;
  148. }
  149. }
  150. DB::commit();
  151. RedisService::keyDel("caches:members:info_*");
  152. RedisService::keyDel("caches:stores:info*");
  153. $this->error = '申请入驻成功,请耐心等候审核~';
  154. return ['id' => $id];
  155. }
  156. /**
  157. * 详情
  158. * @param $id
  159. * @param $userId
  160. * @return array|mixed
  161. */
  162. public function getInfo($id,$userId=0)
  163. {
  164. $cacheKey = "caches:jobs:info_{$id}_{$userId}";
  165. $info = RedisService::get($cacheKey);
  166. if($info){
  167. return $info;
  168. }
  169. $where = ['id'=> $id,'mark'=>1];
  170. $info = $this->model->with(['store','category'])->where($where)->first();
  171. $info = $info? $info->toArray() : [];
  172. if($info){
  173. $info['category_name'] = isset($info['category']) && $info['category']?$info['category']['name'] : '';
  174. RedisService::set($cacheKey, $info, rand(5, 10));
  175. }
  176. return $info;
  177. }
  178. }