wesmiler 6 hónapja
szülő
commit
da9932db10

+ 76 - 0
app/Http/Controllers/Api/v1/ExamController.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Api\ArticleService;
+use App\Services\Api\ExamService;
+
+/**
+ * 考试管理
+ * @package App\Http\Controllers\Api
+ */
+class ExamController extends webApp
+{
+
+    /**
+     * 答题记录
+     * @return array
+     */
+    public function index()
+    {
+        $params =request()->post();
+        $pageSize = request()->post('pageSize', 15);
+        $datas = ExamService::make()->getDataList($params, $pageSize);
+        return message(1010, true, $datas);
+    }
+
+    /**
+     * 答题历史
+     * @return array
+     */
+    public function history()
+    {
+        $params =request()->post();
+        $pageSize = request()->post('pageSize', 15);
+        $datas = ExamService::make()->getHistoryList($params, $pageSize);
+        return message(1010, true, $datas);
+    }
+
+    /**
+     * 详情
+     */
+    public function info()
+    {
+        $params = request()->all();
+        $id = isset($params['id'])? intval($params['id']) : 0;
+        if(empty($id)){
+            return message(1036, false);
+        }
+
+        if($info = ArticleService::make()->getInfo($id)){
+            return message(1010, true, $info);
+        }else{
+            return message(1009, false);
+        }
+    }
+
+
+    /**
+     * 单页数据
+     */
+    public function page()
+    {
+        $params = request()->all();
+        $type = isset($params['type'])? intval($params['type']) : 0;
+        if(empty($type)){
+            return message(1031, false);
+        }
+
+        if($info = ArticleService::make()->getInfoByType($type)){
+            return message(1010, true, $info);
+        }else{
+            return message(1009, false);
+        }
+    }
+}

+ 0 - 39
app/Http/Controllers/Api/v1/MessageController.php

@@ -1,39 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Api\v1;
-
-use App\Http\Controllers\Api\webApp;
-use App\Services\Api\MessageService;
-
-/**
- * 消息管理
- * Class MessageController
- * @package App\Http\Controllers\Api
- */
-class MessageController extends webApp
-{
-    /**
-     * 消息记录
-     * @return array
-     */
-    public function index()
-    {
-        $params = request()->post();
-        $pageSize = request()->post('pageSize', 20);
-        $datas = MessageService::make()->getDataList($params,$pageSize);
-        return message(1010, true, $datas);
-    }
-
-    /**
-     * 站内推送消息历史
-     * @return array|mixed
-     */
-    public function history()
-    {
-        $params = request()->post();
-        $pageSize = request()->post('pageSize', 20);
-        $params['user_id'] = $this->userId;
-        $datas = MessageService::make()->getDataList($params, $pageSize);
-        return message(1010, true, $datas);
-    }
-}

+ 63 - 0
app/Http/Controllers/Api/v1/PaperController.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Api\ArticleService;
+
+/**
+ * 试卷管理
+ * @package App\Http\Controllers\Api
+ */
+class PaperController extends webApp
+{
+
+    /**
+     * 试题列表
+     * @return array
+     */
+    public function index()
+    {
+        $params =request()->post();
+        $pageSize = request()->post('pageSize', 15);
+        $datas = Exa::make()->getDataList($params, $pageSize);
+        return message(1010, true, $datas);
+    }
+
+    /**
+     * 详情
+     */
+    public function info()
+    {
+        $params = request()->all();
+        $id = isset($params['id'])? intval($params['id']) : 0;
+        if(empty($id)){
+            return message(1036, false);
+        }
+
+        if($info = ArticleService::make()->getInfo($id)){
+            return message(1010, true, $info);
+        }else{
+            return message(1009, false);
+        }
+    }
+
+
+    /**
+     * 单页数据
+     */
+    public function page()
+    {
+        $params = request()->all();
+        $type = isset($params['type'])? intval($params['type']) : 0;
+        if(empty($type)){
+            return message(1031, false);
+        }
+
+        if($info = ArticleService::make()->getInfoByType($type)){
+            return message(1010, true, $info);
+        }else{
+            return message(1009, false);
+        }
+    }
+}

+ 12 - 0
app/Models/ExamAccessLogModel.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * 模块访问记录-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Models
+ */
+namespace App\Models;
+class ExamAccessLogModel extends BaseModel
+{
+    protected $table = 'exam_access_logs';
+}

+ 14 - 0
app/Models/ExamAnswerModel.php

@@ -0,0 +1,14 @@
+<?php
+/**
+ * 答题试卷记录-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Models
+ */
+namespace App\Models;
+class ExamAnswerModel extends BaseModel
+{
+    protected $table = 'exam_answers';
+
+
+}

+ 12 - 0
app/Models/ExamAnswerTopicModel.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * 答题题目记录-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Models
+ */
+namespace App\Models;
+class ExamAnswerTopicModel extends BaseModel
+{
+    protected $table = 'exam_answers_topics';
+}

+ 12 - 0
app/Models/ExamErrorModel.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * 纠错记录-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Models
+ */
+namespace App\Models;
+class ExamErrorModel extends BaseModel
+{
+    protected $table = 'exam_errors';
+}

+ 255 - 0
app/Services/Api/ExamService.php

@@ -0,0 +1,255 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Api;
+
+use App\Models\ExamAnswerModel;
+use App\Services\BaseService;
+use App\Services\ConfigService;
+use App\Services\RedisService;
+
+/**
+ * 答题服务-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Services\Api
+ */
+class ExamService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     */
+    public function __construct()
+    {
+        $this->model = new ExamAnswerModel();
+    }
+
+    /**
+     * 静态入口
+     */
+    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)
+    {
+        $page = isset($params['page'])? $params['page'] : 1;
+        $cacheKey = "caches:exams:list_{$page}_{$pageSize}:".md5(json_encode($params));
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $query = $this->getQuery($params);
+        $list = $query->select(['a.id','a.user_id','a.paper_id','a.score','a.accurate_count','b.name','b.type','b.topic_count','b.score_total','b.is_charge','a.create_time','a.answer_times','a.status'])
+            ->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') : '';
+            }
+        }
+
+        $rows = isset($list['data'])? $list['data'] : [];
+        $datas = [
+            'pageSize'=> $pageSize,
+            'total'=> isset($list['total'])? $list['total'] : 0,
+            'list'=> $rows
+        ];
+        if($rows){
+            RedisService::set($cacheKey, $datas, rand(300, 600));
+        }
+
+        return $datas;
+    }
+
+    /**
+     * 查询
+     * @param $params
+     * @return mixed
+     */
+    public function getQuery($params)
+    {
+        $where = ['b.status'=>1,'b.mark'=>1,'a.mark' => 1];
+        $status = isset($params['status'])? $params['status'] : 0;
+        $type = isset($params['type'])? $params['type'] : 0;
+        $sceneType = isset($params['scene_type'])? $params['scene_type'] : 0;
+        $subjectId = isset($params['subject_id'])? $params['subject_id'] : 0;
+        if($status>0){
+            $where['a.status'] = $status;
+        }
+        if($type>0){
+            $where['b.type'] = $type;
+        }
+
+        if($sceneType>0){
+            $where['b.scene_type'] = $sceneType;
+        }
+
+        if($subjectId>0){
+            $where['b.subject_id'] = $subjectId;
+        }
+
+        return $this->model->from('exam_answers as a')
+            ->leftJoin('exam_papers as b','b.id','=','a.paper_id')
+            ->where($where)
+            ->where(function ($query) use($params){
+                $keyword = isset($params['keyword'])? $params['keyword'] : '';
+                if($keyword){
+                    $query->where('b.name','like',"%{$keyword}%");
+                }
+            });
+    }
+
+    /**
+     * 答题历史
+     * @param $params
+     * @param int $pageSize
+     * @return array|mixed
+     */
+    public function getHistoryList($params, $pageSize=10)
+    {
+        $page = isset($params['page'])? $params['page'] : 1;
+        $cacheKey = "caches:exams:history_{$page}_{$pageSize}:".md5(json_encode($params));
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $query = $this->getQuery($params);
+        $list = $query->select(['a.id','a.user_id','a.paper_id','a.score','a.accurate_count','b.name','b.type','b.topic_count','b.score_total','b.is_charge','a.create_time','a.answer_times','a.status'])
+            ->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') : '';
+            }
+        }
+
+        $rows = isset($list['data'])? $list['data'] : [];
+        $datas = [
+            'pageSize'=> $pageSize,
+            'total'=> isset($list['total'])? $list['total'] : 0,
+            'list'=> $rows
+        ];
+        if($rows){
+            RedisService::set($cacheKey, $datas, rand(300, 600));
+        }
+
+        return $datas;
+    }
+
+    /**
+     * 获取文章详情
+     * @param $id
+     * @return array|mixed
+     */
+    public function getInfo($id)
+    {
+        $cacheKey = "caches:articles:info_{$id}";
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+
+        $info = $this->model->where(['id'=> $id,'status'=>1,'mark'=>1])
+            ->select(['id','title','type','cover','view_num','author','description','create_time','type','content'])
+            ->first();
+        $info = $info? $info->toArray() : [];
+        if($info){
+            $info['create_time'] = $info['create_time']? datetime($info['create_time'],'Y-m-d') : '';
+            $info['cover'] = get_image_url($info['cover']);
+            $info['content'] = get_format_content($info['content']);
+            $this->model->where(['id'=> $id])->increment('view_num',1);
+            $info['view_num'] += intval($info['view_num']);
+            RedisService::set($cacheKey, $info, rand(5,10));
+        }
+
+        return $info;
+    }
+
+    /**
+     * 获取分类文章推荐
+     * @param int $cateId 推荐分类ID
+     * @param int $type 类别:3-普通文章,4-客服回复
+     * @return array|mixed
+     */
+    public function getCustomRecommend($cateId=0, $type=4)
+    {
+        $cacheKey = "caches:articles:list_{$cateId}";
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $limitNum = ConfigService::make()->getConfigByCode('custom_recommend_num', 6);
+        $limitNum = $limitNum? $limitNum : 6;
+        $datas = ArticleCateModel::where(function($query) use($cateId){
+                if($cateId){
+                    $query->where('cate_id', $cateId);
+                }
+            })->where(['type'=>$type,'status'=>1,'mark'=>1])
+            ->select(['id','cate_id','title','description','sort','type','status'])
+            ->limit($limitNum)
+            ->orderBy('sort','desc')
+            ->orderBy('create_time','desc')
+            ->get();
+        $datas = $datas? $datas->toArray() : [];
+        if($datas){
+            RedisService::set($cacheKey, $datas, rand(300,600));
+        }
+
+        return $datas;
+    }
+
+    /**
+     * 获取文章推荐分类
+     * @param int $type 1-普通文章分类
+     * @return array|mixed
+     */
+    public function getCateList($type=2)
+    {
+        $cacheKey = "caches:articles:cateList_{$type}";
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $limitNum = ConfigService::make()->getConfigByCode('custom_cate_num', 6);
+        $limitNum = $limitNum? $limitNum : 6;
+        $datas = ArticleCateModel::where(['type'=> $type,'status'=>1,'mark'=>1])
+            ->select(['cate_id','name','sort','type'])
+            ->limit($limitNum)
+            ->get();
+        $datas = $datas? $datas->toArray() : [];
+        if($datas){
+            RedisService::set($cacheKey, $datas, rand(300,600));
+        }
+
+        return $datas;
+    }
+}

+ 0 - 1
app/Services/Exam/TopicService.php

@@ -1,7 +1,6 @@
 <?php
 namespace App\Services\Exam;
 
-use App\Models\ExamTopic;
 use App\Models\ExamTopicModel;
 use App\Services\BaseService;
 use Illuminate\Support\Facades\DB;

+ 1 - 1
app/Services/PaymentService.php

@@ -588,7 +588,7 @@ class PaymentService extends BaseService
                         'source_order_no' => $orderNo,
                         'type' => 1,
                         'money' => $price,
-                        'date' => date('Y-m-d'),
+                        'date' => date('Y-m-d H:i:s'),
                         'create_time' => time(),
                         'remark' => $remark,
                         'status' => 1,

+ 7 - 3
routes/api.php

@@ -68,9 +68,13 @@ Route::prefix('v1')->middleware('web.login')->group(function() {
     Route::get('/order/info', [\App\Http\Controllers\Api\v1\OrderController::class, 'info']);
     Route::post('/order/submit', [\App\Http\Controllers\Api\v1\OrderController::class, 'submit']);
 
-    // 消息列表
-    Route::post('/message/index', [\App\Http\Controllers\Api\v1\MessageController::class, 'index']);
-    Route::post('/message/history', [\App\Http\Controllers\Api\v1\MessageController::class, 'history']);
+    // 答题
+    Route::post('/exam/index', [\App\Http\Controllers\Api\v1\ExamController::class, 'index']);
+    Route::post('/exam/history', [\App\Http\Controllers\Api\v1\ExamController::class, 'history']);
+
+    // 试卷
+    Route::post('/paper/index', [\App\Http\Controllers\Api\v1\MessageController::class, 'index']);
+    Route::post('/paper/subject', [\App\Http\Controllers\Api\v1\MessageController::class, 'subject']);
 
 });