JobsService.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 $userId
  113. * @param $params
  114. * @return mixed
  115. */
  116. public function apply($userId, $params)
  117. {
  118. $name = isset($params['name']) ? trim($params['name']) : '';
  119. $realname = isset($params['real_name']) ? trim($params['real_name']) : '';
  120. $phone = isset($params['phone']) ? trim($params['phone']) : '';
  121. $address = isset($params['address']) ? trim($params['address']) : '';
  122. $categoryId = isset($params['category_id']) ? intval($params['category_id']) : 0;
  123. $logo = isset($params['logo']) && $params['logo']? get_image_path($params['logo']) : '';
  124. $businessLicense = isset($params['business_license']) && $params['business_license']? get_image_path($params['business_license']) : '';
  125. $otherPhoto = isset($params['other_photo']) && $params['other_photo']? get_image_path($params['other_photo']) : '';
  126. $data = [
  127. 'user_id' => $userId,
  128. 'name' => $name,
  129. 'real_name' => $realname,
  130. 'phone' => $phone,
  131. 'address' => $address,
  132. 'category_id' => $categoryId,
  133. 'logo' => $logo,
  134. 'business_license' => $businessLicense,
  135. 'other_photo' => $otherPhoto,
  136. 'order_count' => 0,
  137. 'order_total' => 0,
  138. 'confirm_remark' => '',
  139. 'create_time' => time(),
  140. 'update_time' => time(),
  141. 'status' => 2,
  142. 'mark' => 1,
  143. ];
  144. DB::beginTransaction();
  145. if($id = $this->model->where(['user_id'=>$userId])->value('id')){
  146. $this->model->where(['id'=>$id])->update($data);
  147. }else{
  148. if (!$id = $this->model->insertGetId($data)) {
  149. DB::rollBack();
  150. $this->error = '申请入驻失败';
  151. return false;
  152. }
  153. }
  154. DB::commit();
  155. RedisService::keyDel("caches:members:info_*");
  156. RedisService::keyDel("caches:stores:info*");
  157. $this->error = '申请入驻成功,请耐心等候审核~';
  158. return ['id' => $id];
  159. }
  160. /**
  161. * 详情
  162. * @param $id
  163. * @param $userId
  164. * @return array|mixed
  165. */
  166. public function getInfo($id,$userId=0)
  167. {
  168. $cacheKey = "caches:jobs:info_{$id}_{$userId}";
  169. $info = RedisService::get($cacheKey);
  170. if($info){
  171. return $info;
  172. }
  173. $where = ['id'=> $id,'mark'=>1];
  174. $info = $this->model->with(['store','category'])->where($where)->first();
  175. $info = $info? $info->toArray() : [];
  176. if($info){
  177. $info['category_name'] = isset($info['category']) && $info['category']?$info['category']['name'] : '';
  178. RedisService::set($cacheKey, $info, rand(5, 10));
  179. }
  180. return $info;
  181. }
  182. }