新版数智员工

This commit is contained in:
wong
2026-03-24 10:39:16 +08:00
parent 1853934d85
commit 7fb61b77a4
123 changed files with 38491 additions and 1018 deletions

View File

@@ -4,9 +4,13 @@ namespace app\store\model;
use think\Model;
/**
* 用户流量套餐模型
*/
class UserFlowPackageModel extends Model
{
protected $name = 'user_flow_package';
/**
* 获取用户当前有效的流量套餐
*
@@ -25,79 +29,5 @@ class UserFlowPackageModel extends Model
->order('expireTime', 'asc') // 按到期时间排序,最先到期的排在前面
->find();
}
/**
* 创建用户套餐订阅记录
*
* @param int $userId 用户ID
* @param int $packageId 套餐ID
* @param int $duration 套餐时长(月)
* @return bool 是否创建成功
*/
public static function createSubscription($userId, $packageId, $duration = 0)
{
if (empty($userId) || empty($packageId)) {
return false;
}
// 获取套餐信息
$package = FlowPackageModel::where('id', $packageId)->where('isDel', 0)->find();
if (empty($package)) {
return false;
}
// 如果未指定时长,则使用套餐默认时长
if (empty($duration)) {
$duration = $package['duration'];
}
// 计算开始时间和到期时间
$now = time();
$startTime = $now;
$expireTime = strtotime("+{$duration} month", $now);
// 创建新订阅
$data = [
'userId' => $userId,
'packageId' => $packageId,
'duration' => $duration,
'totalFlow' => $package->totalFlow,
'usedFlow' => 0,
'status' => 1, // 1表示有效
'startTime' => $startTime,
'expireTime' => $expireTime,
'createTime' => $now,
'updateTime' => $now
];
return self::create($data) ? true : false;
}
/**
* 更新用户已使用流量
*
* @param int $id 用户套餐ID
* @param int $usedFlow 已使用流量
* @return bool 是否更新成功
*/
public static function updateUsedFlow($id, $usedFlow)
{
if (empty($id)) {
return false;
}
$userPackage = self::where('id', $id)->find();
if (empty($userPackage)) {
return false;
}
// 确保使用量不超过总量
$maxFlow = $userPackage['totalFlow'];
$usedFlow = $usedFlow > $maxFlow ? $maxFlow : $usedFlow;
return self::where('id', $id)->update([
'usedFlow' => $usedFlow,
'updateTime' => time()
]) ? true : false;
}
}
}