47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\api\logic\user;
|
||
|
|
||
|
use app\common\logic\BaseLogic;
|
||
|
use app\common\model\store_visit\StoreVisit;
|
||
|
use app\common\model\user\UserVisit;
|
||
|
use think\facade\Db;
|
||
|
|
||
|
class UserVisitLogic extends BaseLogic
|
||
|
{
|
||
|
/**
|
||
|
* @notes 添加用户访问
|
||
|
* @param array $params
|
||
|
* @return bool
|
||
|
* @author likeadmin
|
||
|
* @date 2024/05/13 16:56
|
||
|
*/
|
||
|
public static function add(array $params,$uid): bool
|
||
|
{
|
||
|
Db::startTrans();
|
||
|
try {
|
||
|
$check = StoreVisit::where(['product_id'=>$params['product_id'],
|
||
|
'uid'=>$uid
|
||
|
])
|
||
|
->whereDay('create_time')
|
||
|
->find();
|
||
|
if($check){
|
||
|
StoreVisit::where('id',$check['id'])->inc('count')->update();
|
||
|
}else{
|
||
|
StoreVisit::create([
|
||
|
'uid' => $uid,
|
||
|
'product_id' => $params['product_id'],
|
||
|
'cate_id' => $params['cate_id'],
|
||
|
'count' => 1,
|
||
|
'create_time' => time(),
|
||
|
]);
|
||
|
}
|
||
|
Db::commit();
|
||
|
return true;
|
||
|
} catch (\Exception $e) {
|
||
|
Db::rollback();
|
||
|
self::setError($e->getMessage());
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|