58 lines
1.1 KiB
PHP
58 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace app\api\model\app\exchange;
|
|
|
|
use think\Model;
|
|
use think\Db;
|
|
use app\api\model\app\agent\Level;
|
|
class Batch extends Model
|
|
{
|
|
|
|
|
|
// 表名
|
|
protected $name = 'app_exchange_batch';
|
|
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'integer';
|
|
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'createtime';
|
|
protected $updateTime = false;
|
|
protected $deleteTime = false;
|
|
|
|
// 追加属性
|
|
protected $append = [
|
|
];
|
|
|
|
|
|
/**
|
|
* 检查是否超出批次兑换限制
|
|
* @param $userId
|
|
* @param $code
|
|
* @return void true=未超限制;false=超出限制
|
|
*/
|
|
public function checkLimit($userId,$batchId){
|
|
|
|
$batchInfo = self::where([
|
|
'id'=>$batchId
|
|
])->find();
|
|
|
|
if(!$batchInfo){
|
|
return false;
|
|
}
|
|
|
|
//不限制
|
|
if(!$batchInfo['use_limit']){
|
|
return true;
|
|
}
|
|
|
|
$exchangeCount = \app\api\model\app\exchange\UseLog::getExchangeCount($userId,$batchId);
|
|
|
|
if($exchangeCount < $batchInfo['use_limit']){
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |