85 lines
2.4 KiB
PHP
85 lines
2.4 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,
|
|
'store_id' => $params['store_id']??0,
|
|
'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;
|
|
}
|
|
}
|
|
|
|
|
|
public static function visitAdd(array $params,$userInfo): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$check = UserVisit::where(['url'=>$params['url'],
|
|
'uid'=>$userInfo['user_id']
|
|
])
|
|
->whereDay('create_time')
|
|
->find();
|
|
if($check){
|
|
UserVisit::where('id',$check['id'])->inc('stay_time',$params['stay_time'])->update();
|
|
}else{
|
|
UserVisit::create([
|
|
'uid' => $userInfo['user_id'],
|
|
'url' => $params['url'],
|
|
'channel_type' =>$userInfo['terminal'],
|
|
'ip' => $params['ip'],
|
|
'stay_time' => $params['stay_time'],
|
|
'create_time' => time(),
|
|
]);
|
|
}
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} |