Browse Source

wesmiler 报恩寺项目提交

wesmiler 4 years ago
parent
commit
c66ff3ef6e

+ 57 - 0
app/Http/Controllers/Api/v1/ArticleController.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\BaseController;
+use App\Http\Validator\ArticleValidator;
+use App\Services\ArticleBooksService;
+use App\Services\ArticleService;
+use Illuminate\Http\Request;
+
+/**
+ * 文章头条控制器类
+ * @author wesmiler
+ * @since 2020/11/10
+ * Class ArticleController
+ * @package App\Http\Controllers
+ */
+class ArticleController extends BaseController
+{
+    /**
+     * 构造函数
+     * @author wesmiler
+     * @since 2020/11/11
+     * ArticleController constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->service = new ArticleService();
+        $this->bookService = new ArticleBooksService();
+    }
+
+    /**
+     * 列表
+     * @return array
+     */
+    public function index(){
+        $params = request()->all();
+        return $this->service->getDataList($params);
+    }
+
+    /**
+     * 报名
+     * @param Request $request
+     * @param ArticleValidator $validate
+     * @return array
+     */
+    public function books(Request $request, ArticleValidator $validate){
+        $params = $validate->check($request->all(),'books');
+        if(!is_array($params)){
+            return message($params, false);
+        }
+        $params['user_id'] = $this->userId;
+        return $this->bookService->books($params);
+    }
+}

+ 57 - 0
app/Http/Controllers/Api/v1/WorkController.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\BaseController;
+use App\Http\Validator\WorkValidator;
+use App\Services\WorkBooksService;
+use App\Services\WorkService;
+use Illuminate\Http\Request;
+
+/**
+ * 文章头条控制器类
+ * @author wesmiler
+ * @since 2020/11/10
+ * Class WorkController
+ * @package App\Http\Controllers
+ */
+class WorkController extends BaseController
+{
+    /**
+     * 构造函数
+     * @author wesmiler
+     * @since 2020/11/11
+     * WorkController constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->service = new WorkService();
+        $this->bookService = new WorkBooksService();
+    }
+
+    /**
+     * 列表
+     * @return array
+     */
+    public function index(){
+        $params = request()->all();
+        return $this->service->getDataList($params);
+    }
+
+    /**
+     * 报名
+     * @param Request $request
+     * @param WorkValidator $validate
+     * @return array
+     */
+    public function books(Request $request, WorkValidator $validate){
+        $params = $validate->check($request->all(),'books');
+        if(!is_array($params)){
+            return message($params, false);
+        }
+        $params['user_id'] = $this->userId;
+        return $this->bookService->books($params);
+    }
+}

+ 45 - 0
app/Http/Validator/ArticleValidator.php

@@ -0,0 +1,45 @@
+<?php
+namespace App\Http\Validator;
+class ArticleValidator extends BaseValidator
+{
+    // 当前模型所有验证规则
+    public static $rules = [
+        'id' => 'required',
+        'realname' => 'required|string|min:1|max:20',
+        'phone' => 'required|string|min:2|max:20',
+    ];
+
+    // 当前模型所有错误提示信息
+    public static $msgs = [
+        'required' => ':attribute不能为空',
+        'string' => ':attribute必须是字符串',
+        'min' => ':attribute长度不能小于:min位',
+        'max' => ':attribute长度不能大于:max位',
+        'exists' => ':attribute不存在',
+        'rule' => ':attribute格式不正确',
+    ];
+
+    // 当前模型所有验证字段
+    public static $fields = [
+        'id' => 'ID',
+        'realname' => '姓名',
+        'phone' => '联系电话',
+    ];
+
+    // 当前模型所有验证场景
+    public static $scenes = [
+        'info'=> ['id'],
+        'books'=> ['id','realname','phone'],
+    ];
+
+    /**
+     * 验证
+     * @param $request
+     * @param string $scene
+     * @return int|mixed
+     */
+    public static function check($request, $scene=''){
+        $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
+        return $validator->checkParams($request, $scene);
+    }
+}

+ 45 - 0
app/Http/Validator/WorkValidator.php

@@ -0,0 +1,45 @@
+<?php
+namespace App\Http\Validator;
+class WorkValidator extends BaseValidator
+{
+    // 当前模型所有验证规则
+    public static $rules = [
+        'id' => 'required',
+        'realname' => 'required|string|min:1|max:20',
+        'phone' => 'required|string|min:2|max:20',
+    ];
+
+    // 当前模型所有错误提示信息
+    public static $msgs = [
+        'required' => ':attribute不能为空',
+        'string' => ':attribute必须是字符串',
+        'min' => ':attribute长度不能小于:min位',
+        'max' => ':attribute长度不能大于:max位',
+        'exists' => ':attribute不存在',
+        'rule' => ':attribute格式不正确',
+    ];
+
+    // 当前模型所有验证字段
+    public static $fields = [
+        'id' => 'ID',
+        'realname' => '姓名',
+        'phone' => '联系电话',
+    ];
+
+    // 当前模型所有验证场景
+    public static $scenes = [
+        'info'=> ['id'],
+        'books'=> ['id','realname','phone'],
+    ];
+
+    /**
+     * 验证
+     * @param $request
+     * @param string $scene
+     * @return int|mixed
+     */
+    public static function check($request, $scene=''){
+        $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
+        return $validator->checkParams($request, $scene);
+    }
+}

+ 42 - 0
app/Services/ArticleBooksService.php

@@ -12,6 +12,7 @@
 namespace App\Services;
 
 use App\Models\ArticleBooksModel;
+use App\Models\MemberModel;
 
 /**
  * 文章分类管理-服务类
@@ -103,4 +104,45 @@ class ArticleBooksService extends BaseService
         return parent::edit($data); // TODO: Change the autogenerated stub
     }
 
+    /**
+     * 报名
+     * @parpam array $params 参数
+     * @return array
+     * @since 2020/11/11
+     * @author wesmiler
+     */
+    public function books($params)
+    {
+        $userId = isset($params['user_id'])? $params['user_id'] : 0;
+        $memberInfo = MemberModel::where(['id'=> $userId,'maek'=> 1,'status'=> 1])
+            ->select(['id','nickname','openid'])
+            ->first();
+        if(!$memberInfo){
+            return message('用户状态不可操作,请联系客服', false);
+        }
+
+        // 是否报名过
+        $aid = isset($params['id'])? intval($params['id']) : 0;
+        $info = $this->model::where(['aid'=> $aid,'user_id'=> $userId, 'mark'=> 1,'status'=> 1])
+            ->where('create_time','>=', strtotime(date('Y-m-d')))
+            ->first();
+        if($info){
+            return message('该信息下您今日已经提交过信息', false);
+        }
+
+        $data = [
+            'aid'=> $aid,
+            'user_id'=> $userId,
+            'realname'=> isset($params['realname'])? trim($params['realname']) : '',
+            'phone'=> isset($params['phone'])? trim($params['phone']) : '',
+            'thumb'=> isset($params['thumb'])? trim($params['thumb']) : '',
+            'description'=> isset($params['description'])? trim($params['description']) : '',
+            'create_time'=> time(),
+            'mark'=> 1,
+            'status'=> 1
+        ];
+
+        $data['update_time'] = time();
+        return parent::edit($data); // TODO: Change the autogenerated stub
+    }
 }

+ 85 - 0
app/Services/ArticleService.php

@@ -67,6 +67,11 @@ class ArticleService extends BaseService
                     $query->where('a.is_top', $isTop);
                 }
 
+                $type = isset($params['type']) ? intval($params['type']) : 0;
+                if ($type > 0) {
+                    $query->where('a.type', $type);
+                }
+
 
                 $status = isset($params['status']) ? $params['status'] : 0;
                 if ($status > 0) {
@@ -99,6 +104,86 @@ class ArticleService extends BaseService
     }
 
     /**
+     * 获取列表
+     * @return array
+     * @since 2020/11/11
+     * @author wesmiler
+     */
+    public function getDataList($params)
+    {
+        $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
+        $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
+
+        $dataList = $this->model::from('article as a')
+            ->leftJoin('article_cates as c', 'a.cate_id', '=', 'c.id')
+            ->where(function ($query) use ($params) {
+                $query->where(['a.mark'=>1,'a.status'=> 1]);
+
+                $title = isset($params['title']) ? trim($params['title']) : '';
+                if (!empty($title)) {
+                    $query->where('a.title', 'like', "%{$title}%");
+                }
+
+                $cateId = isset($params['cate_id']) ? intval($params['cate_id']) : 0;
+                if ($cateId > 0) {
+                    $query->where('a.cate_id', $cateId);
+                } else if ($cateId == -1) {
+                    $query->where('a.is_recommand', 1);
+                }
+
+                $isTop = isset($params['is_top']) ? intval($params['is_top']) : 0;
+                if ($isTop > 0) {
+                    $query->where('a.is_top', $isTop);
+                }
+
+                $type = isset($params['type']) ? intval($params['type']) : 0;
+                if ($type > 0) {
+                    $query->where('a.type', $type);
+                }
+
+            })
+            ->select(['a.id', 'a.cate_id', 'c.name as cate_name', 'a.title', 'a.is_form', 'a.is_recommand', 'a.view_num', 'a.thumb', 'a.status', 'a.create_time', 'a.update_time', 'a.description', 'a.sort','a.publish_at'])
+            ->orderBy('a.update_time', 'desc')
+            ->paginate($pageSize);
+
+        $dataList = $dataList ? $dataList->toArray() : [];
+        if ($dataList) {
+            foreach ($dataList['data'] as &$item) {
+                $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : '';
+                $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
+                $item['publish_at'] = $item['publish_at'] ? $item['publish_at'] : $item['create_at'];
+            }
+            unset($item);
+        }
+
+        return [
+            'code' => 0,
+            'success'=> true,
+            'msg' => '操作成功',
+            'count' => isset($dataList['total']) ? $dataList['total'] : 0,
+            'data' => isset($dataList['data']) ? $dataList['data'] : 0,
+        ];
+    }
+
+    /**
+     * 获取详情
+     * @param $id
+     */
+    public function getDetail($id){
+        $info = $this->model::from('article as a')
+            ->leftJoin('article_cates as c', 'a.cate_id', '=', 'c.id')
+            ->where(['a.mark'=> 1,'a.status'=> 1,'a.id'=> $id])
+            ->select(['a.id','a.title','a.thumb','a.cate_id','c.name as cate_name','a.view_num','a.description','a.content','a.publish_at','a.create_time'])
+            ->first();
+        $info = $info? $info->toArray() : [];
+        if($info){
+            $info['thumb'] = $info['thumb']? get_image_url($info['thumb']) : '';
+            $info['publish_at'] = $info['publish_at']? $info['publish_at'] : datetime( $info['create_time'],'Y-m-d H:i:s');
+
+        }
+    }
+
+    /**
      * 添加或编辑
      * @return array
      * @since 2020/11/11

+ 43 - 0
app/Services/WorkBooksService.php

@@ -11,6 +11,7 @@
 
 namespace App\Services;
 
+use App\Models\MemberModel;
 use App\Models\WorkBooksModel;
 
 /**
@@ -103,4 +104,46 @@ class WorkBooksService extends BaseService
         return parent::edit($data); // TODO: Change the autogenerated stub
     }
 
+
+    /**
+     * 报名
+     * @parpam array $params 参数
+     * @return array
+     * @since 2020/11/11
+     * @author wesmiler
+     */
+    public function books($params)
+    {
+        $userId = isset($params['user_id'])? $params['user_id'] : 0;
+        $memberInfo = MemberModel::where(['id'=> $userId,'maek'=> 1,'status'=> 1])
+            ->select(['id','nickname','openid'])
+            ->first();
+        if(!$memberInfo){
+            return message('用户状态不可操作,请联系客服', false);
+        }
+
+        // 是否报名过
+        $aid = isset($params['id'])? intval($params['id']) : 0;
+        $info = $this->model::where(['aid'=> $aid,'user_id'=> $userId, 'mark'=> 1,'status'=> 1])
+            ->where('create_time','>=', strtotime(date('Y-m-d')))
+            ->first();
+        if($info){
+            return message('该信息下您今日已经提交过信息', false);
+        }
+
+        $data = [
+            'aid'=> $aid,
+            'user_id'=> $userId,
+            'realname'=> isset($params['realname'])? trim($params['realname']) : '',
+            'phone'=> isset($params['phone'])? trim($params['phone']) : '',
+            'thumb'=> isset($params['thumb'])? trim($params['thumb']) : '',
+            'description'=> isset($params['description'])? trim($params['description']) : '',
+            'create_time'=> time(),
+            'mark'=> 1,
+            'status'=> 1
+        ];
+
+        $data['update_time'] = time();
+        return parent::edit($data); // TODO: Change the autogenerated stub
+    }
 }

+ 44 - 5
app/Services/WorkService.php

@@ -55,11 +55,6 @@ class WorkService extends BaseService
                     $query->where('a.title', 'like', "%{$title}%");
                 }
 
-                $cateId = isset($params['cate_id']) ? intval($params['cate_id']) : 0;
-                if ($cateId > 0) {
-                    $query->where('a.cate_id', $cateId);
-                }
-
                 $status = isset($params['status']) ? $params['status'] : 0;
                 if ($status > 0) {
                     $query->where('a.status', $status);
@@ -91,6 +86,50 @@ class WorkService extends BaseService
     }
 
     /**
+     * 获取列表
+     * @return array
+     * @since 2020/11/11
+     * @author wesmiler
+     */
+    public function getDataList($params)
+    {
+        $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
+        $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
+
+        $dataList = $this->model::from('works as a')
+            ->where(function ($query) use ($params) {
+                $query->where(['a.mark'=> 1,'a.status'=> 1]);
+
+                $title = isset($params['title']) ? trim($params['title']) : '';
+                if (!empty($title)) {
+                    $query->where('a.title', 'like', "%{$title}%");
+                }
+
+            })
+            ->select(['a.id', 'a.title', 'a.view_num','a.num', 'a.thumb', 'a.status', 'a.create_time', 'a.update_time', 'a.description', 'a.sort', 'a.content','a.publish_at'])
+            ->orderBy('a.update_time', 'desc')
+            ->paginate($pageSize);
+
+        $dataList = $dataList ? $dataList->toArray() : [];
+        if ($dataList) {
+            foreach ($dataList['data'] as &$item) {
+                $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : '';
+                $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
+                $item['publish_at'] = $item['publish_at'] ? $item['publish_at'] : $item['create_at'];
+            }
+            unset($item);
+        }
+
+        return [
+            'code' => 0,
+            'success'=> true,
+            'msg' => '操作成功',
+            'count' => isset($dataList['total']) ? $dataList['total'] : 0,
+            'data' => isset($dataList['data']) ? $dataList['data'] : 0,
+        ];
+    }
+
+    /**
      * 添加或编辑
      * @return array
      * @since 2020/11/11

+ 11 - 0
routes/api.php

@@ -80,3 +80,14 @@ Route::post('/order/list', [\App\Http\Controllers\Api\v1\OrderController::class,
 Route::post('/recharge/params', [\App\Http\Controllers\Api\v1\RechargeController::class, 'params']);
 Route::post('/recharge/list', [\App\Http\Controllers\Api\v1\RechargeController::class, 'index']);
 Route::post('/recharge/pay', [\App\Http\Controllers\Api\v1\RechargeController::class, 'pay']);
+
+
+// 文章头条
+Route::post('/article/list', [\App\Http\Controllers\Api\v1\ArticleController::class, 'index']);
+Route::post('/article/info', [\App\Http\Controllers\Api\v1\ArticleController::class, 'info']);
+Route::post('/article/books', [\App\Http\Controllers\Api\v1\ArticleController::class, 'books']);
+
+// 工作招聘
+Route::post('/work/list', [\App\Http\Controllers\Api\v1\ArticleController::class, 'index']);
+Route::post('/work/info', [\App\Http\Controllers\Api\v1\ArticleController::class, 'info']);
+Route::post('/work/books', [\App\Http\Controllers\Api\v1\ArticleController::class, 'books']);