初始化项目:添加后端代码、ThinkPHP框架、前端资源

This commit is contained in:
amb
2026-09-03 12:42:39 +08:00
commit 482bece22e
3726 changed files with 416708 additions and 0 deletions
@@ -0,0 +1,58 @@
<?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;
}
}
@@ -0,0 +1,98 @@
<?php
namespace app\api\model\app\exchange;
use think\Model;
use think\Db;
use app\api\model\app\agent\Level;
class Code extends Model
{
// 表名
protected $name = 'app_exchange_code';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
/**
* 检查兑换码
* @param $code
* @return void
*/
public function checkCode($code)
{
//判断有没有
$data = self::with(['batch'])->where([
'code'=>$code,
'code.status'=>1,
'batch.status'=>1,
'batch.starttime'=>['<',time()],
'batch.endtime'=>['>',time()]
])->find();
if(!$data){
return false;
}
return $data;
}
public function batch()
{
return $this->belongsTo('Batch', 'batch_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
/**
* 兑换
* @param $userId 用户
* @param $goodsId 商品
* @return bool
*/
public function exchange($userId,$batchId,$code)
{
$goods = \app\api\model\app\exchange\Goods::getBatchGoods($batchId);
if($goods){
$subscriptionModel = new \app\common\model\user\Subscription();
foreach ($goods as $item){
$subscriptionModel->setUserCourse($userId,$item['goods_id'],'exchange');
\app\api\model\app\exchange\UseLog::insert([
'user_id'=>$userId,
'uniacid'=>UNIACID,
'goods_id'=>$item['goods_id'],
'code'=>$code,
'batch_id'=>$batchId,
'createtime'=>time()
]);
self::where([
'code'=>$code,
'batch_id'=>$batchId
])->update([
'user_id'=>$userId,
'use_time'=>time(),
'status'=>2
]);
}
}
return true;
}
}
@@ -0,0 +1,46 @@
<?php
namespace app\api\model\app\exchange;
use think\Model;
use think\Db;
use app\api\model\app\agent\Level;
class Goods extends Model
{
// 表名
protected $name = 'app_exchange_batch_goods';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
/**
* 获取批次包含的商品
* @return void
*/
public static function getBatchGoods($batchId){
return self::with('course')->where([
'batch_id'=>$batchId
])->select();
}
public function course()
{
return $this->belongsTo('app\api\model\course\Course', 'goods_id', 'id', [], 'RIGHT')->setEagerlyType(0);
}
}
@@ -0,0 +1,54 @@
<?php
namespace app\api\model\app\exchange;
use think\Model;
use think\Db;
use app\api\model\app\agent\Level;
class UseLog extends Model
{
// 表名
protected $name = 'app_exchange_use_log';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
/**
* 获取兑换次数
* @param $userId 用户
* @param $batchId 批次
* @return mixed
*/
public static function getExchangeCount($userId,$batchId){
return self::where([
'user_id'=>$userId,
'batch_id'=>$batchId
])->group('code')->count();
}
public function batch()
{
return $this->belongsTo('Batch', 'batch_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function course()
{
return $this->belongsTo('app\api\model\course\Course', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}