Files
MBTI_wang/api/app/model/GaokaoPricing.php
Ghost c4ac0f8a08 feat: 高考志愿与定价分销链路更新(管理端/API/小程序)
- 新增高考志愿核心服务、模型、控制器与迁移脚本

- 同步管理端定价/分销/设置与小程序入口、历史、测试选择和支付逻辑

- 补充相关开发文档

Made-with: Cursor
2026-04-25 16:19:08 +08:00

61 lines
1.6 KiB
PHP

<?php
namespace app\model;
use think\Model;
/**
* 高考定价配置
*/
class GaokaoPricing extends Model
{
protected $name = 'gaokao_pricing';
protected $schema = [
'id' => 'int',
'tenantId' => 'int',
'productCode' => 'string',
'productName' => 'string',
'priceOriginal' => 'int',
'priceSale' => 'int',
'priceChannel' => 'int',
'currency' => 'string',
'status' => 'int',
'effectiveAt' => 'int',
'expiredAt' => 'int',
'extraJson' => 'string',
'createdAt' => 'int',
'updatedAt' => 'int',
];
protected $autoWriteTimestamp = 'int';
protected $createTime = 'createdAt';
protected $updateTime = 'updatedAt';
protected $json = ['extraJson'];
/**
* 命中某租户、商品在当前时间生效的定价(租户优先,平台兜底)
*/
public static function resolveByTenantAndProduct(int $tenantId, string $productCode): ?self
{
$now = time();
$base = self::where('productCode', $productCode)
->where('status', 1)
->where('effectiveAt', '<=', $now)
->where(function ($q) use ($now) {
$q->whereNull('expiredAt')->whereOr('expiredAt', 0)->whereOr('expiredAt', '>', $now);
})
->order('id', 'desc');
if ($tenantId > 0) {
$row = (clone $base)->where('tenantId', $tenantId)->find();
if ($row) {
return $row;
}
}
return (clone $base)->where('tenantId', 0)->find();
}
}