初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\app\exam;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 题库练习订阅
|
||||
*/
|
||||
class ExercisesSubscribe extends Model
|
||||
{
|
||||
// 表名,不含前缀
|
||||
protected $name = 'app_exam_exercises_subscribe';
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = false;
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = false;
|
||||
protected $updateTime = false;
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 增加订阅
|
||||
* @param $userId 用户
|
||||
* @param $exercisesId 练习ID
|
||||
* @param $type 订阅方式
|
||||
* @return void
|
||||
*/
|
||||
public static function subscribe($userId,$exercisesId,$type = ''){
|
||||
self::insert([
|
||||
'user_id'=>$userId,
|
||||
'exercises_id'=>$exercisesId,
|
||||
'type'=>$type,
|
||||
'createtime'=>time(),
|
||||
'uniacid'=>UNIACID
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否订阅
|
||||
* @param $userId
|
||||
* @param $exercisesId
|
||||
* @return void
|
||||
*/
|
||||
public static function checkSubscribe($userId,$exercisesId){
|
||||
$data = self::where([
|
||||
'user_id'=>$userId,
|
||||
'exercises_id'=>$exercisesId
|
||||
])->find();
|
||||
|
||||
if($data){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有使用权限
|
||||
* @param $userId
|
||||
* @param $exercisesId
|
||||
* @return void
|
||||
*/
|
||||
public static function checkAuth($userId,$exercisesId){
|
||||
|
||||
$exercises = \app\common\model\app\exam\Exercises::where([
|
||||
'id'=>$exercisesId,
|
||||
'status'=>1
|
||||
])->find();
|
||||
|
||||
if(!$exercises){
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($exercises['sales_type']){
|
||||
case 1:
|
||||
return true;
|
||||
break;
|
||||
case 2:
|
||||
$isSubscribe = self::checkSubscribe($userId,$exercisesId);
|
||||
if($isSubscribe){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
//关联课程 判断课程订阅权限
|
||||
if(\app\common\model\user\Subscription::getSubscriptionAuth($userId,$exercises['bind_course'])){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user