兼容修改
This commit is contained in:
parent
ca0bf11b55
commit
29d521d744
18
.env.example
18
.env.example
|
|
@ -1,18 +0,0 @@
|
|||
APP_DEBUG = true
|
||||
URL = http://192.168.1.43:1333/
|
||||
|
||||
DEFAULT_TIMEZONE = Asia/Shanghai
|
||||
|
||||
default_lang = zh-cn
|
||||
|
||||
|
||||
HOSTNAME = rm-gc712o11yndj78x6a6o.mysql.cn-chengdu.rds.aliyuncs.com
|
||||
USERNAME = video_user
|
||||
PASSWORD = VideoUser@1
|
||||
HOSTPORT = 3306
|
||||
|
||||
SLAVE_HOSTNAME = rm-gc712o11yndj78x6a6o.mysql.cn-chengdu.rds.aliyuncs.com
|
||||
SLAVE_USERNAME = video_user
|
||||
SLAVE_PASSWORD = VideoUser@1
|
||||
SLAVE_HOSTPORT = 3306
|
||||
|
||||
|
|
@ -199,10 +199,10 @@ class Orders extends BaseModel
|
|||
|
||||
|
||||
// TODO 异步领取奖励
|
||||
// pushQueue(ActivitiesQueue::class, [
|
||||
// 'userInfo' => $userInfo,
|
||||
// 'sourceUser' => $byUser
|
||||
// ], 1);
|
||||
pushQueue(ActivitiesQueue::class, [
|
||||
'userInfo' => $userInfo,
|
||||
'sourceUser' => $byUser
|
||||
], 1);
|
||||
DatabaseRoute::transactionXa(function () use ($userInfo, $byUser, $userId) {
|
||||
self::activities($userInfo, $byUser);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace app\command;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\queue\DiscCompensateJob;
|
||||
use app\queue\redis\DiscCompensateJob;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
|
|
|||
|
|
@ -7,187 +7,21 @@ use app\api\model\CourseDetails;
|
|||
use app\api\model\TbUser;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\model\Test;
|
||||
use app\queue\redis\ActivitiesQueue;
|
||||
use support\Request;
|
||||
use think\facade\Db;
|
||||
use Webman\RedisQueue\Client;
|
||||
|
||||
class IndexController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
\support\Log::info('来了' . date('Y-m-d H:i:s'));
|
||||
$get['courseId'] = $course_id = '1877654905222135809';
|
||||
$user['user_id'] = $user_id = '14240';
|
||||
$user = DatabaseRoute::getDb('tb_user', $user_id)->find();
|
||||
try {
|
||||
if(empty($get['courseId'])) {
|
||||
return json('参数不完整');
|
||||
}
|
||||
$courseId = $get['courseId'];
|
||||
// 获取短剧详情
|
||||
$dd_b = Db::connect('duanju_slave');
|
||||
$db_name = $dd_b->name('course');
|
||||
$bean = $db_name->where(['course_id' => $courseId])->find();
|
||||
if(!$bean) {
|
||||
return json('短剧不存在');
|
||||
}
|
||||
// Client::send('test', [], 0);
|
||||
|
||||
|
||||
$courseCollect = DatabaseRoute::getDb('course_collect', $user_id)
|
||||
->where(['course_id' => $course_id])
|
||||
->where(['user_id' => $user_id])
|
||||
->where(['classify' => 3])
|
||||
->limit(1)
|
||||
->find();
|
||||
|
||||
|
||||
|
||||
// 是否追剧
|
||||
$collect = DatabaseRoute::getDb('course_collect', $user_id)
|
||||
->where(['course_id' => $course_id])
|
||||
->where(['classify' => 1])
|
||||
->limit(1)
|
||||
->find();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$db = Db::connect(config('think-orm.search_library'));
|
||||
$userVip = $db->name('user_vip')->where(['user_id' => $user['user_id']])->find();
|
||||
|
||||
if ($userVip) {
|
||||
$user['member'] = $userVip['is_vip'];
|
||||
$user['end_time'] = $userVip['end_time'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$userInfo = $user;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!empty($userInfo['member']) && $userInfo['member'] == 2) {
|
||||
$isVip = true;
|
||||
}else{
|
||||
$isVip = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 查询用户是否购买了整集
|
||||
$courseUser = DatabaseRoute::getDb('course_user', $user_id)
|
||||
->where(['course_id' => $course_id])
|
||||
->where(['classify' => 1])
|
||||
->find();
|
||||
|
||||
|
||||
|
||||
// 每天购买超过上限,获得免费时间段资格
|
||||
$freeWatch = Test::checkFreeWatchPayCount($user['user_id']);
|
||||
|
||||
$startSort = 0;
|
||||
$endSort = 5;
|
||||
$dn_course_details = DatabaseRoute::getDb('course_details', ['course_id' => $courseId]);
|
||||
$sort = null;
|
||||
if (is_null($sort)) {
|
||||
|
||||
if (!empty($courseCollect)) {
|
||||
$courseDetails = $dn_course_details->field('sort')
|
||||
->where('course_details_id', $courseCollect['course_details_id'])
|
||||
->limit(1)
|
||||
->find();
|
||||
$sort = $courseDetails['sort'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($freeWatch || !empty($courseUser)) {
|
||||
$courseDetailsSetVos = Test::courseSets($courseId, 2, null);
|
||||
} else {
|
||||
$courseDetailsSetVos = Test::courseSets($courseId, 1, $bean['wholesale_price']);
|
||||
}
|
||||
|
||||
// 调整集数范围
|
||||
if (!is_null($sort) && $sort > 2) {
|
||||
$startSort = $sort - 3;
|
||||
$endSort = $sort + 3;
|
||||
if (count($courseDetailsSetVos) < $endSort) {
|
||||
$startSort = count($courseDetailsSetVos) - 5;
|
||||
$endSort = count($courseDetailsSetVos) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 已购买剧集ID集合
|
||||
$detailsId = [];
|
||||
if (!$freeWatch) {
|
||||
$det_db = Db::connect(DatabaseRoute::getConnection('course_user', ['user_id' => $user['user_id']]));
|
||||
$detailsId = $det_db->name('course_user')->where(['course_id' => $courseId, 'classify' => 2])->column('course_details_id');
|
||||
$det_db->close();
|
||||
$detailsId = array_flip(array_flip($detailsId)); // 去重
|
||||
\support\Log::info('啦啦啦' . date('Y-m-d H:i:s'));
|
||||
}
|
||||
// 处理剧集列表
|
||||
$current = null;
|
||||
foreach ($courseDetailsSetVos as &$s) {
|
||||
$s['wholesalePrice'] = (int) $s['wholesalePrice'];
|
||||
// 当前播放集
|
||||
if (!empty($courseCollect) && $s['courseDetailsId'] == $courseCollect['course_details_id']) {
|
||||
$s['current'] = 1;
|
||||
$current = &$s;
|
||||
}
|
||||
|
||||
// 非免费用户的权限控制
|
||||
if (
|
||||
!$freeWatch &&
|
||||
$s['sort'] > 3 &&
|
||||
(empty($detailsId) || !in_array($s['courseDetailsId'], $detailsId)) &&
|
||||
empty($courseUser) &&
|
||||
!$isVip
|
||||
) {
|
||||
$s['videoUrl'] = null;
|
||||
}
|
||||
|
||||
// 检查是否已点赞
|
||||
if ($s['sort'] > $startSort && $s['sort'] < $endSort) {
|
||||
$isGood_db = Db::connect(DatabaseRoute::getConnection('course_collect', ['user_id' => $user['user_id']]));
|
||||
$isGood = $isGood_db->name('course_collect')
|
||||
->where('course_details_id', $s['courseDetailsId'])
|
||||
->where('classify', 2)
|
||||
->limit(1)
|
||||
->count();
|
||||
$isGood_db->close();
|
||||
$s['isGood'] = empty($isGood) || $isGood == 0 ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有当前播放集,默认第一集
|
||||
if (empty($current) && !empty($courseDetailsSetVos)) {
|
||||
$courseDetailsSetVos[0]['current'] = 1;
|
||||
$current = &$courseDetailsSetVos[0];
|
||||
}
|
||||
Test::setCourseView($bean);
|
||||
|
||||
$price = ($freeWatch ? 0 : ($bean['price'] ?? 0));
|
||||
$price = bccomp($price, '0', 2) <= 0 ? 0 : $price;
|
||||
// 返回结果
|
||||
$map = [
|
||||
'current' => $current,
|
||||
'price' => $price,
|
||||
'title' => $bean['title'],
|
||||
'collect' => empty($collect) || $collect == 0 ? 0 : 1,
|
||||
'list' => $courseDetailsSetVos
|
||||
];
|
||||
\support\Log::info('即将返回' . date('Y-m-d H:i:s'));
|
||||
return json($map);
|
||||
} catch (\Exception $e) {
|
||||
return json($e->getMessage());
|
||||
}
|
||||
pushQueue(ActivitiesQueue::class, [
|
||||
'userInfo' => 1,
|
||||
'sourceUser' => 1
|
||||
], 1);
|
||||
}
|
||||
|
||||
public function view(Request $request)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
// 应用公共文件
|
||||
|
||||
use support\Log;
|
||||
use support\think\Cache;
|
||||
use Webman\RedisQueue\Client;
|
||||
|
||||
if (!function_exists('__')) {
|
||||
|
||||
|
|
@ -1012,18 +1014,15 @@ if(!function_exists('extract_target_user_ids')) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
function pushQueue($class, $data=[], $seconds=0)
|
||||
{
|
||||
$queue = class_basename($class);
|
||||
$data[] = [
|
||||
'queueId' => uuid(),
|
||||
];
|
||||
Log::info("消息队列发送消息,对列名: $class, 携带数据: ".json_encode($data).', 延时时间: '.$seconds);
|
||||
if ($seconds > 0) {
|
||||
Queue::later($seconds, $class, $data);
|
||||
}else{
|
||||
Queue::push($class, $data);
|
||||
}
|
||||
Log::info("消息队列发送消息,对列名: $queue, 携带数据: ".json_encode($data).', 延时时间: '.$seconds);
|
||||
// 投递延迟消息,消息会在60秒后处理
|
||||
Client::send($queue, $data, $seconds);
|
||||
}
|
||||
|
||||
if(!function_exists('daysBetween')) {
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\queue;
|
||||
|
||||
use app\api\model\Orders;
|
||||
use app\api\model\UserMoney;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Log;
|
||||
use think\queue\Job;
|
||||
|
||||
/**
|
||||
* 奖项领取
|
||||
*/
|
||||
class ActivitiesQueue extends BaseQueue
|
||||
{
|
||||
public function run(Job $job, $data)
|
||||
{
|
||||
Orders::activities($data['userInfo'], $data['sourceUser']);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\queue;
|
||||
|
||||
use think\facade\Log;
|
||||
use think\queue\Job;
|
||||
|
||||
abstract class BaseQueue
|
||||
{
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
$start = microtime(true);
|
||||
try {
|
||||
Log::info("消息队列接收到消息,当前队列: ".self::class.", 携带数据: ".json_encode($data));
|
||||
$this->run($job, $data);
|
||||
Log::info("消息队列执行成功:" . static::class);
|
||||
$job->delete();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error("消息队列执行异常:" . $e->getMessage());
|
||||
Log::info($e->getTraceAsString());
|
||||
$job->release(10); // 或 $job->fail()
|
||||
}
|
||||
|
||||
$end = microtime(true);
|
||||
Log::info("消息队列执行完毕, 耗时:" . ($end - $start) . 's');
|
||||
}
|
||||
|
||||
// 子类实现具体逻辑
|
||||
abstract public function run(Job $job, $data);
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\queue;
|
||||
|
||||
use app\admin\model\DiscSpinning;
|
||||
use think\facade\Log;
|
||||
use think\queue\Job;
|
||||
|
||||
class DiscCompensateJob
|
||||
{
|
||||
|
||||
public function fire(Job $job, $data) {
|
||||
try {
|
||||
Log::write('准备处理DiscCompensateJob' . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
DiscSpinning::receive1($data);
|
||||
$job->delete(); // 处理成功删除任务
|
||||
} catch (\Exception $e) {
|
||||
if ($job->attempts() < 3) {
|
||||
$job->release(5); // 重试3次,间隔5秒
|
||||
} else {
|
||||
$job->delete();
|
||||
Log::error("大转盘补偿任务最终失败:ID={$data['id']}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
|
||||
/**
|
||||
* 奖项领取
|
||||
*/
|
||||
class ActivitiesQueue extends BaseQueue implements Consumer
|
||||
{
|
||||
public function run($data)
|
||||
{
|
||||
Log::info("哈哈哈哈");
|
||||
// Orders::activities($data['userInfo'], $data['sourceUser']);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
|
||||
abstract class BaseQueue
|
||||
{
|
||||
public $queue;
|
||||
public $connection = 'default';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->queue = class_basename(static::class);
|
||||
Log::info("消息队列启动成功,".$this->queue);
|
||||
}
|
||||
|
||||
public function consume( $data)
|
||||
{
|
||||
$start = microtime(true);
|
||||
Log::info("消息队列接收到消息,当前队列: ".self::class.", 携带数据: ".json_encode($data));
|
||||
$this->run($data);
|
||||
$end = microtime(true);
|
||||
Log::info("消息队列执行完毕, 耗时:" . ($end - $start) . 's');
|
||||
}
|
||||
|
||||
public function onConsumeFailure(\Throwable $e, $package)
|
||||
{
|
||||
Log::error("消息队列执行异常:" . $e->getMessage());
|
||||
Log::info($e->getTraceAsString());
|
||||
}
|
||||
|
||||
// 子类实现具体逻辑
|
||||
abstract public function run($data);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\admin\model\DiscSpinning;
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
|
||||
class DiscCompensateJob extends BaseQueue implements Consumer
|
||||
{
|
||||
|
||||
public function run( $data) {
|
||||
Log::write('准备处理DiscCompensateJob' . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
DiscSpinning::receive1($data);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace app\queue;
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\api\model\UserMoney;
|
||||
use app\common\library\DatabaseRoute;
|
||||
|
|
@ -12,7 +12,7 @@ use think\queue\Job;
|
|||
*/
|
||||
class DiscReceiveQueue extends BaseQueue
|
||||
{
|
||||
public function run(Job $job, $data)
|
||||
public function run( $data)
|
||||
{
|
||||
$drawsInfo = $data['draws'];
|
||||
if ($drawsInfo['type'] != 2) {
|
||||
|
|
@ -1,19 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace app\queue;
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\admin\controller\Cash;
|
||||
use app\api\model\UserMoney;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Log;
|
||||
use think\queue\Job;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
|
||||
/**
|
||||
* 奖项领取
|
||||
*/
|
||||
class UserPushQueue extends BaseQueue
|
||||
class UserPushQueue extends BaseQueue implements Consumer
|
||||
{
|
||||
public function run(Job $job, $data)
|
||||
public function run($data)
|
||||
{
|
||||
$userInfoList = $data['list'];
|
||||
foreach ($userInfoList as $userInfo) {
|
||||
|
|
@ -26,14 +26,14 @@ class WuYouPayUtils
|
|||
}
|
||||
$booted = true;
|
||||
|
||||
self::$mchId = config('wuyou.merchant_id', '');
|
||||
self::$payUrl = config('wuyou.url', '');
|
||||
self::$notifyUrl = config('wuyou.notify_url', '');
|
||||
self::$h5BaseUrl = config('wuyou.h5_base_url', '');
|
||||
self::$secret = config('wuyou.secret', '');
|
||||
self::$extractUrl = config('wuyou.extract_url', '');
|
||||
self::$extractNotifyUrl = config('wuyou.extract_notify_url', '');
|
||||
self::$queryUrl = config('wuyou.query_url', '');
|
||||
self::$mchId = '100360';
|
||||
self::$payUrl = 'http://47.113.117.120/api/order';
|
||||
self::$notifyUrl = 'https://ph.hnsiyao.cn/api/wuyou/notify';
|
||||
self::$h5BaseUrl = 'https://ph.hnsiyao.cn/api/wuyou/notify';
|
||||
self::$secret = '3MWSBmyKDeQDLXzoLr53tKVqiJv4Fm0KdsEhbpXW9YWvh35VgozL5S3rpUz4EjSb';
|
||||
self::$extractUrl = 'http://47.113.117.120/api/salary';
|
||||
self::$extractNotifyUrl = 'http://47.113.117.120/api/salary';
|
||||
self::$queryUrl = 'http://47.113.117.120/api/queryOrder';
|
||||
|
||||
if (hasEmpty(self::$mchId, self::$payUrl, self::$notifyUrl, self::$h5BaseUrl, self::$secret)) {
|
||||
throw new SysException('缺少必要参数');
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
"ext-bcmath": "*",
|
||||
"webman/redis": "^2.1",
|
||||
"illuminate/events": "^11.45",
|
||||
"webman/redis-queue": "^2.1",
|
||||
"webman/console": "^2.1"
|
||||
},
|
||||
"suggest": {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Webman\RedisQueue\Command\MakeConsumerCommand;
|
||||
|
||||
return [
|
||||
MakeConsumerCommand::class
|
||||
];
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'handlers' => [
|
||||
[
|
||||
'class' => Monolog\Handler\RotatingFileHandler::class,
|
||||
'constructor' => [
|
||||
runtime_path() . '/logs/redis-queue/queue.log',
|
||||
7, //$maxFiles
|
||||
Monolog\Logger::DEBUG,
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
'constructor' => [null, 'Y-m-d H:i:s', true],
|
||||
],
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
return [
|
||||
'consumer' => [
|
||||
'handler' => Webman\RedisQueue\Process\Consumer::class,
|
||||
'count' => 8, // 可以设置多进程同时消费
|
||||
'constructor' => [
|
||||
// 消费者类目录
|
||||
'consumer_dir' => app_path() . '/queue/redis'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
return [
|
||||
'default' => [
|
||||
'host' => 'redis://127.0.0.1:6379',
|
||||
'options' => [
|
||||
'auth' => null,
|
||||
'db' => 0,
|
||||
'prefix' => '',
|
||||
'max_attempts' => 5,
|
||||
'retry_seconds' => 5,
|
||||
],
|
||||
// Connection pool, supports only Swoole or Swow drivers.
|
||||
'pool' => [
|
||||
'max_connections' => 5,
|
||||
'min_connections' => 1,
|
||||
'wait_timeout' => 3,
|
||||
'idle_timeout' => 60,
|
||||
'heartbeat_interval' => 50,
|
||||
]
|
||||
],
|
||||
];
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
location / {
|
||||
if (!-e $request_filename) {
|
||||
rewrite ^(.*)$ /index.php?s=/$1 last;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue