$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; } }