94 lines
2.4 KiB
PHP
94 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace app\common\model\course;
|
|
|
|
use think\Model;
|
|
use app\api\model\course\ColumnBind;
|
|
use app\common\model\user\Subscription;
|
|
use app\common\exception\Exception;
|
|
class Course extends Model
|
|
{
|
|
|
|
// 表名
|
|
protected $name = 'course';
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'integer';
|
|
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'createtime';
|
|
protected $updateTime = false;
|
|
protected $deleteTime = false;
|
|
|
|
|
|
/**
|
|
* 获取课程价格
|
|
* @param $id
|
|
* @return array
|
|
*/
|
|
public static function getPrice($id){
|
|
$data = self::get($id);
|
|
|
|
if(!$data){
|
|
return false;
|
|
}
|
|
|
|
$buyData = [
|
|
'pay_type'=>$data['pay_type'],
|
|
'price'=>$data['price'],
|
|
'sales_type'=>json_decode($data['sales_type'],true)
|
|
];
|
|
|
|
if($data['pay_type'] != 'free'){
|
|
//判断是否在专栏中设置了试看
|
|
//如果专栏是免费的,那么专栏下的所有课程都可查看
|
|
$columnBind = ColumnBind::with([
|
|
'column'
|
|
])->where(function ($query) use ($data) {
|
|
$query->where([
|
|
'course_id'=>$data['id'],
|
|
'try'=>1,
|
|
'column.status'=>1,
|
|
'column.uniacid'=>UNIACID
|
|
]);
|
|
})->whereOr(function ($query) use ($data) {
|
|
$query->where([
|
|
'course_id'=>$data['id'],
|
|
'column.status'=>1,
|
|
'column.pay_type'=>'free',
|
|
'column.uniacid'=>UNIACID
|
|
]);
|
|
})->field(["column.id"])->select();
|
|
|
|
if($columnBind){
|
|
$buyData['pay_type'] = 'free';
|
|
}
|
|
}
|
|
|
|
return $buyData;
|
|
}
|
|
|
|
|
|
/**
|
|
* 检查课程销售类型
|
|
* @param $row 课程详情
|
|
* @return false
|
|
*/
|
|
public static function checkSalesType($row){
|
|
|
|
$row['sales_type'] = json_decode($row['sales_type'],true);
|
|
|
|
if($row['type'] != 'column' && (!$row['sales_type'] || !in_array("alone",$row['sales_type']))){
|
|
throw new Exception("该课程未开启单独售卖");
|
|
}
|
|
|
|
if($row['type'] == 'column' && !in_array("alone",$row['sales_type'])){
|
|
throw new Exception("该专栏未开启单独售卖");
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
}
|