xxxrrrdddd 3 年之前
父节点
当前提交
36ba9f6ddf
共有 2 个文件被更改,包括 14 次插入0 次删除
  1. 2 0
      application/api/controller/MobileController.php
  2. 12 0
      application/common/model/Mobile.php

+ 2 - 0
application/api/controller/MobileController.php

@@ -159,6 +159,8 @@ class MobileController extends UserApi
             'id'=>['require']
         ]);
         $mobile=Mobile::where('id','id')->with(['info'])->findOrFail($data['id']);
+        $mobile->addViewCount();
+        $mobile->append(['view_count']);
         $this->success('',$mobile);
     }
     /**

+ 12 - 0
application/common/model/Mobile.php

@@ -4,6 +4,7 @@ namespace app\common\model;
 
 use app\admin\model\Admin;
 use app\common\service\MobileComputer;
+use think\Cache;
 use think\Model;
 use traits\model\SoftDelete;
 
@@ -172,4 +173,15 @@ class Mobile extends Model
             throw_user('该号码已售或不存在');
         }
     }
+
+    public function viewCountCacheName(){
+        return __CLASS__."view_count_{$this['id']}_".date('ymdh');
+    }
+    public function getViewCountAttr(){
+        return Cache::get($this->viewCountCacheName(),0);
+    }
+    public function addViewCount(){
+        $num=Cache::get($this->viewCountCacheName(),0);
+        Cache::set($this->viewCountCacheName(),$num+1);
+    }
 }