83 lines
2.2 KiB
PHP
83 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace app\api\model;
|
|
|
|
use app\common\library\DatabaseRoute;
|
|
use app\common\model\Common;
|
|
use app\utils\RedisUtils;
|
|
use ba\Random;
|
|
use think\facade\Cache;
|
|
use think\facade\Db;
|
|
use think\facade\Log;
|
|
use think\Model;
|
|
|
|
class CourseCollect extends Model
|
|
{
|
|
|
|
// 观看记录
|
|
public static function Watchhistory($user_id, $course_id)
|
|
{
|
|
return DatabaseRoute::getDb('course_collect', $user_id)
|
|
->where(['course_id' => $course_id])
|
|
->where(['user_id' => $user_id])
|
|
->where(['classify' => 3])
|
|
->limit(1)
|
|
->find();
|
|
}
|
|
|
|
|
|
// 是否追剧
|
|
public static function isfollowthedrama($user_id, $course_id)
|
|
{
|
|
return DatabaseRoute::getDb('course_collect', $user_id)
|
|
->where(['course_id' => $course_id])
|
|
->where(['classify' => 1])
|
|
->limit(1)
|
|
->find();
|
|
}
|
|
|
|
// 查询用户是否购买了整集
|
|
public static function selectCourseUser($user_id, $course_id)
|
|
{
|
|
return DatabaseRoute::getDb('course_user', $user_id)
|
|
->where(['course_id' => $course_id])
|
|
->where(['classify' => 1])
|
|
->find();
|
|
}
|
|
|
|
|
|
/**
|
|
* 校验用户是否达到免费播放购买次数
|
|
*/
|
|
public static function checkFreeWatchPayCount($userId)
|
|
{
|
|
$isExpire = RedisUtils::getFreeWatchTimeIsExpire($userId);
|
|
|
|
if (!$isExpire) {
|
|
$count = DatabaseRoute::getDb('orders', $userId)->where([
|
|
'status' => 1,
|
|
'pay_way' => 9,
|
|
['create_time', '>', date('Y-m-d 00:00:00')],
|
|
])->count();
|
|
$needCount = (new CommonInfo())->getByCode(916);
|
|
$freeTime = (new CommonInfo())->getByCode(917);
|
|
if (!$needCount || !$freeTime) {
|
|
return false;
|
|
}
|
|
|
|
if ($count >= intval($needCount['value'])) {
|
|
RedisUtils::setFreeWatchTime($userId, intval($freeTime['value']) * 60, false);
|
|
RedisUtils::getFreeWatchTimeIsExpire($userId);
|
|
$isExpire = false;
|
|
}else{
|
|
$isExpire = true;
|
|
}
|
|
}
|
|
|
|
return !$isExpire;
|
|
}
|
|
|
|
|
|
|
|
|
|
} |