wesmiler преди 3 месеца
родител
ревизия
26949258d5

+ 78 - 0
app/Http/Controllers/Api/v1/JobsController.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Api\JobsService;
+
+/**
+ * 招聘信息
+ * @package App\Http\Controllers\Api
+ */
+class JobsController extends webApp
+{
+
+    /**
+     * 列表
+     * @return array
+     */
+    public function index()
+    {
+        $params =request()->post();
+        $pageSize = request()->post('pageSize', 15);
+        $datas = JobsService::make()->getDataList($params, $pageSize);
+        return showJson(1010, true, $datas);
+    }
+
+
+    /**
+     * 分类
+     * @return array
+     */
+    public function categorys()
+    {
+        $datas = JobsService::make()->getCategoryList();
+        return showJson(1010, true, $datas);
+    }
+
+    /**
+     * 详情
+     * @return array
+     */
+    public function info()
+    {
+        $params = request()->all();
+        $id = isset($params['id'])? $params['id'] : 0;
+        try {
+            if(!$result = JobsService::make()->getInfo($id, $this->userId)){
+                return showJson(1009, false);
+            }else{
+                return showJson(1010, true, $result);
+            }
+        } catch (\Exception $exception) {
+            $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
+            return showJson(1046, false, $error);
+        }
+    }
+
+    /**
+     * 申请
+     * @return array
+     */
+    public function apply()
+    {
+        $params = request()->all();
+
+       try {
+           if(!$result = JobsService::make()->apply($this->userId, $params)){
+               return showJson(JobsService::make()->getError(), false);
+           }else{
+               return showJson(JobsService::make()->getError(), true, $result);
+           }
+       } catch (\Exception $exception) {
+           $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
+           return showJson(1046, false, $error);
+       }
+    }
+
+}

+ 0 - 1
app/Services/Api/AccountService.php

@@ -19,7 +19,6 @@ use App\Services\BaseService;
 use App\Services\PaymentService;
 use App\Services\RedisService;
 use Illuminate\Support\Facades\DB;
-use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
 
 /**
  * 交易管理-服务类

+ 1 - 1
app/Services/Api/AgentService.php

@@ -19,7 +19,7 @@ use App\Services\RedisService;
  * 代理管理-服务类
  * @author laravel开发员
  * @since 2020/11/11
- * @package App\Services\Common
+ * @package App\Services\Api
  */
 class AgentService extends BaseService
 {

+ 1 - 1
app/Services/Api/ComplaintService.php

@@ -20,7 +20,7 @@ use App\Services\RedisService;
  * @author laravel开发员
  * @since 2020/11/11
  * Class ComplaintService
- * @package App\Services\Common
+ * @package App\Services\Api
  */
 class ComplaintService extends BaseService
 {

+ 196 - 0
app/Services/Api/JobsService.php

@@ -0,0 +1,196 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Api;
+
+use App\Models\JobsCategoryModel;
+use App\Models\JobsModel;
+use App\Services\BaseService;
+use App\Services\RedisService;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 招聘管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Services\Api
+ */
+class JobsService extends BaseService
+{
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     */
+    public function __construct()
+    {
+        $this->model = new JobsModel();
+    }
+
+    /**
+     * 静态入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = (new static());
+        }
+        return self::$instance;
+    }
+
+    /**
+     * @param $params
+     * @param int $pageSize
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1];
+        $status = isset($params['status']) ? $params['status'] : 0;
+        if ($status > 0) {
+            $where['a.status'] = $status;
+        }
+        $list = $this->model->with(['store','category'])->from('jobs as a')
+            ->leftJoin('jobs_categorys as b', 'b.id', '=', 'a.category_id')
+            ->where($where)
+            ->where(function ($query) use ($params) {
+                $keyword = isset($params['keyword']) ? $params['keyword'] : '';
+                if ($keyword) {
+                    $query->where('a.job_name', 'like', "%{$keyword}%")
+                    ->orWhere('a.job_title','like',"%{$keyword}%")
+                    ->orWhere('a.tags','like',"%{$keyword}%")
+                    ->orWhere('a.company','like',"%{$keyword}%");
+                }
+            })
+            ->select(['a.*'])
+            ->orderBy('a.create_time', 'desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list ? $list->toArray() : [];
+        if ($list) {
+            foreach ($list['data'] as &$item) {
+                $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
+            }
+        }
+
+        return [
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'list' => isset($list['data']) ? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 分类
+     * @return array|mixed
+     */
+    public function getCategoryList()
+    {
+        $cacheKey = "caches:jobs:categoryList";
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $datas = JobsCategoryModel::where(['pid'=>0,'status'=>1,'mark'=>1])
+            ->select(['id','name','pid','remark','sort'])
+            ->orderBy('sort','desc')
+            ->orderBy('id','desc')
+            ->get();
+        $datas = $datas? $datas->toArray() : [];
+        if($datas){
+            RedisService::set($cacheKey, $datas, rand(300,600));
+        }
+
+        return $datas;
+    }
+
+
+    /**
+     * 申请
+     * @param $userId
+     * @param $params
+     * @return mixed
+     */
+    public function apply($userId, $params)
+    {
+        $name = isset($params['name']) ? trim($params['name']) : '';
+        $realname = isset($params['real_name']) ? trim($params['real_name']) : '';
+        $phone = isset($params['phone']) ? trim($params['phone']) : '';
+        $address = isset($params['address']) ? trim($params['address']) : '';
+        $categoryId = isset($params['category_id']) ? intval($params['category_id']) : 0;
+        $logo = isset($params['logo']) && $params['logo']? get_image_path($params['logo']) : '';
+        $businessLicense = isset($params['business_license']) && $params['business_license']? get_image_path($params['business_license']) : '';
+        $otherPhoto = isset($params['other_photo']) && $params['other_photo']? get_image_path($params['other_photo']) : '';
+
+        $data = [
+            'user_id' => $userId,
+            'name' => $name,
+            'real_name' => $realname,
+            'phone' => $phone,
+            'address' => $address,
+            'category_id' => $categoryId,
+            'logo' => $logo,
+            'business_license' => $businessLicense,
+            'other_photo' => $otherPhoto,
+            'order_count' => 0,
+            'order_total' => 0,
+            'confirm_remark' => '',
+            'create_time' => time(),
+            'update_time' => time(),
+            'status' => 2,
+            'mark' => 1,
+        ];
+
+        DB::beginTransaction();
+        if($id = $this->model->where(['user_id'=>$userId])->value('id')){
+            $this->model->where(['id'=>$id])->update($data);
+        }else{
+            if (!$id = $this->model->insertGetId($data)) {
+                DB::rollBack();
+                $this->error = '申请入驻失败';
+                return false;
+            }
+        }
+
+        DB::commit();
+        RedisService::keyDel("caches:members:info_*");
+        RedisService::keyDel("caches:stores:info*");
+        $this->error = '申请入驻成功,请耐心等候审核~';
+        return ['id' => $id];
+    }
+
+    /**
+     * 详情
+     * @param $id
+     * @param $userId
+     * @return array|mixed
+     */
+    public function getInfo($id,$userId=0)
+    {
+        $cacheKey = "caches:jobs:info_{$id}_{$userId}";
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+        $where = ['id'=> $id,'mark'=>1];
+        $info = $this->model->with(['store','category'])->where($where)->first();
+        $info = $info? $info->toArray() : [];
+        if($info){
+            $info['category_name'] = isset($info['category']) && $info['category']?$info['category']['name'] : '';
+            RedisService::set($cacheKey, $info, rand(5, 10));
+        }
+
+        return $info;
+    }
+
+
+}

+ 1 - 1
app/Services/Api/MemberAddressService.php

@@ -21,7 +21,7 @@ use Illuminate\Support\Facades\DB;
  * @author laravel开发员
  * @since 2020/11/11
  * Class MemberAddressService
- * @package App\Services\Common
+ * @package App\Services\Api
  */
 class MemberAddressService extends BaseService
 {

+ 1 - 1
app/Services/Api/SettleService.php

@@ -25,7 +25,7 @@ use Illuminate\Support\Facades\DB;
  * 结算管理-服务类
  * @author laravel开发员
  * @since 2020/11/11
- * @package App\Services\Common
+ * @package App\Services\Api
  */
 class SettleService extends BaseService
 {

+ 0 - 1
app/Services/Api/SocialCircleService.php

@@ -11,7 +11,6 @@
 
 namespace App\Services\Api;
 
-use App\Models\NoticeModel;
 use App\Models\SocialCircleModel;
 use App\Services\BaseService;
 use App\Services\ConfigService;

+ 1 - 3
app/Services/Api/StoreService.php

@@ -13,9 +13,7 @@ namespace App\Services\Api;
 
 use App\Models\StoreCategoryModel;
 use App\Models\StoreModel;
-use App\Models\UserModel;
 use App\Services\BaseService;
-use App\Services\Common\UserRoleService;
 use App\Services\RedisService;
 use Illuminate\Support\Facades\DB;
 
@@ -23,7 +21,7 @@ use Illuminate\Support\Facades\DB;
  * 商家管理-服务类
  * @author laravel开发员
  * @since 2020/11/11
- * @package App\Services\Common
+ * @package App\Services\Api
  */
 class StoreService extends BaseService
 {

+ 5 - 0
routes/api.php

@@ -115,6 +115,11 @@ Route::prefix('v1')->middleware('web.login')->group(function() {
     Route::post('/agent/info', [\App\Http\Controllers\Api\v1\AgentController::class, 'info']);
     Route::post('/agent/apply', [\App\Http\Controllers\Api\v1\AgentController::class, 'apply']);
 
+    // 招聘
+    Route::post('/job/index', [\App\Http\Controllers\Api\v1\JobsController::class, 'index']);
+    Route::post('/job/info', [\App\Http\Controllers\Api\v1\JobsController::class, 'info']);
+    Route::post('/job/apply', [\App\Http\Controllers\Api\v1\JobsController::class, 'apply']);
+    Route::post('/job/categorys', [\App\Http\Controllers\Api\v1\JobsController::class, 'categorys']);
 
 
 });