moonsflyer il y a 7 mois
Parent
commit
feb81772f7

+ 18 - 1
app/api/controller/ServiceController.php

@@ -30,7 +30,7 @@ use app\api\lists\service\ServiceLists;
 class ServiceController extends BaseApiController
 {
 
-    public array $notNeedLogin = ['getServiceList','getAreaList','getCateList','getServiceInfo','autoUpdateStatus','getServiceContent','getServiceDisclaimer'];
+    public array $notNeedLogin = ['getServiceList','getAreaList','getCateList','getServiceInfo','autoUpdateStatus','getServiceContent','getServiceDisclaimer','addScanLog'];
 
 
     /**
@@ -176,4 +176,21 @@ class ServiceController extends BaseApiController
         return $this->data($result);
     }
 
+    public function addScanLog(){
+        if($this->request->isPost()) {
+
+            $params = (new ServiceValidate())->post()->goCheck('log');
+            $userId = $this->userId;
+            $params['user_id'] = $userId;
+            $result = ServiceLogic::addLog($params);
+            if (true === $result) {
+
+                return $this->success('日志插入成功', [], 1, 1);
+            }
+            return $this->fail(ServiceLogic::getError());
+
+        }else{
+            return $this->fail('请求方式错误');
+        }
+    }
 }

+ 29 - 0
app/api/logic/ServiceLogic.php

@@ -28,6 +28,7 @@ use app\common\service\{
 };
 use app\common\model\agricultural_machinery\UserService;
 use app\common\model\agricultural_machinery\ServiceCategory;
+use app\common\model\agricultural_machinery\ServiceScanLog;
 use app\common\model\ServiceCharge;
 use app\common\model\asset\AssetArea;
 use app\common\model\recharge\RechargeOrder;
@@ -326,4 +327,32 @@ class ServiceLogic extends BaseLogic
         $data['disclaimer'] = ConfigService::get('website', 'disclaimer');
         return $data;
     }
+
+    /**
+     * @notes 插入浏览日志
+     * @param array $params
+     * @return bool
+     * @author 段誉
+     * @date 2022/9/7 15:37
+     */
+    public static function addLog(array $params)
+    {
+        try {
+
+            $data = [
+                'sn' => generate_sn(RechargeOrder::class, 'sn'),
+                'user_id' => $params['user_id'],
+                'type' => $params['log_type'],
+                'service_user_id' => $params['service_user_id']??0,
+
+            ];
+             ServiceScanLog::create($data);
+
+            return true;
+        } catch (\Exception $e) {
+
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
 }

+ 3 - 0
app/api/validate/ServiceValidate.php

@@ -49,6 +49,7 @@ class ServiceValidate extends BaseValidate
         'images'=>'require',
         'content'=>'require',
         'money' => 'require|float|egt:0',
+        'log_type'=> 'require|in:0,1,2,3',
     ];
 
 
@@ -71,12 +72,14 @@ class ServiceValidate extends BaseValidate
         'driver_image.require'                  => '请上传驾驶证图片',
         'driving_image.require'                 => '请上传行驶证图片',
         'agricultural_image.require'            => '请上传农机图片',
+        'log_type.in'                               =>'类型log_type参数规则错误',
     ];
     protected $scene = [
         'agricultural_machinery_operator' => ['name','mobile','type','cate_id','area_id','agricultural_machinery_model','images','driver_image','driving_image','agricultural_image'], //
         'info' => ['type'], //
         'cate'=>['type'],
         'serviceRenew'=>['type'],
+        'log'=>['log_type']
     ];
 
     /**

+ 33 - 0
app/common/model/agricultural_machinery/ServiceScanLog.php

@@ -0,0 +1,33 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\model\agricultural_machinery;
+
+use app\common\model\agricultural_machinery\ServiceCategory;
+use app\common\model\BaseModel;
+use app\common\model\asset\AssetArea;
+use app\common\model\recharge\RechargeOrder;
+use app\common\service\FileService;
+use app\common\model\user\User;
+use think\model\concern\SoftDelete;
+
+/**
+ * 浏览记录模型
+ * Class ArticleCate
+ * @package app\common\model\article;
+ */
+class ServiceScanLog extends BaseModel
+{
+
+}