webman_duanju/app/model/Test.php

112 lines
3.2 KiB
PHP

<?php
namespace app\model;
use support\Log;
use think\model;
use think\facade\Db;
use app\common\library\DatabaseRoute;
class Test extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'test';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
public static function checkFreeWatchPayCount($userId)
{
$count = DatabaseRoute::getDb('orders', $userId)->where([
'status' => 1,
'pay_way' => 9,
['create_time', '>', date('Y-m-d 00:00:00')],
])->count();
$needCount = Db::name('common_info')->where([
'type' => 916
])->find();
$freeTime = Db::name('common_info')->where([
'type' => 917
])->find();
if (!$needCount || !$freeTime) {
return false;
}
if ($count >= intval($needCount['value'])) {
$isExpire = false;
}else{
$isExpire = true;
}
Log::info('嘿嘿' . date('Y-m-d H:i:s'));
return !$isExpire;
}
public static function courseSets($courseId, $isPrice, $wholesalePrice)
{
$db = Db::connect(DatabaseRoute::getConnection('course_details', ['course_id' => $courseId]));
$courseDetailsSetVos = $db->name('course_details')
->alias('c')
->field([
'c.course_id' => 'courseId',
'c.course_details_id' => 'courseDetailsId',
'c.course_details_name' => 'courseDetailsName',
'c.video_url' => 'videoUrl',
'c.price' => 'price',
'c.sort' => 'sort',
'c.is_price' => 'isPrice',
'c.title_img' => 'titleImg',
'c.good_num' => 'goodNum',
])
->where('c.course_id', $courseId)
->order('c.sort', 'asc')
->select()
->toArray();
foreach ($courseDetailsSetVos as $k => &$v) {
$v['courseId'] = (string) $v['courseId'];
$v['courseDetailsId'] = (string) $v['courseDetailsId'];
if(empty($wholesalePrice)) {
$v['wholesalePrice'] = 0;
}else {
$v['wholesalePrice'] = $wholesalePrice;
}
if($isPrice != 1) {
$v['isPrice'] = 2;
}
}
return $courseDetailsSetVos;
}
public static function setCourseView($course)
{
// 1. 更新总播放量
if (empty($course['view_counts'])) {
$viewCounts = 1;
} else {
$viewCounts = $course['view_counts'] + 1;
}
$db_name = Db::connect(config('think-orm.z_library'))->name('course');
// 4. 执行数据库更新
$db_name->where(['course_id' => $course['course_id']])->update([
'view_counts' => $viewCounts,
'week_view' => 999
]);
}
}