1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\models\store;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- use app\admin\model\user\User;
- class StoreVisit extends BaseModel
- {
-
- protected $pk = 'id';
-
- protected $name = 'store_visit';
- use ModelTrait;
-
- public static function setView($uid, $product_id = 0, $cate = 0, $type = '', $content = '', $min = 20)
- {
- $model = new self();
- $view = $model->where('uid', $uid)->where('product_id', $product_id)->field('count,add_time,id')->find();
- if ($view && $type != 'search') {
- $time = time();
- if (($view['add_time'] + $min) < $time) {
- $model->where(['id' => $view['id']])->update(['count' => $view['count'] + 1, 'add_time' => time()]);
- }
- } else {
- $cate = explode(',', $cate)[0];
- $model->insert([
- 'add_time' => time(),
- 'count' => 1,
- 'product_id' => $product_id,
- 'cate_id' => $cate,
- 'type' => $type,
- 'uid' => $uid,
- 'content' => $content
- ]);
- }
- }
- }
|