提交 52c02d62 authored 作者: qhz's avatar qhz

【开发】 xxl-job php 执行器

上级
流水线 #52472 已失败 于阶段
APP_NAME=skeleton
APP_ENV=dev
#开发阶段,请不要设置 scan_cacheable 为 true,它会导致 收集器缓存 存在时,不会再次扫描文件
scan_cacheable=false
# 进程数
APP_WORKER_NUM=1
# HTTP服务地址
SWOOLE_HTTP_HOST=0.0.0.0
# HTTP服务端口
SWOOLE_HTTP_PORT=9511
# ------------------- 日志配置 ---------------------------------------------------------------------
# 日志路径,不设置环境变量为 BASE_PATH . '/runtime/logs',生产环境建议设置为 其他目录
# LOG_BASE_PATH=/tmp/logs
# 日志级别,可选值为 DEBUG|INFO|NOTICE|WARNING|ERROR|CRITICAL|ALERT|EMERGENCY
LOG_LEVEL_DEFAULT=DEBUG
# 日志保存时间,日志按天分割,超过指定天数会被删除
LOG_MAX_FILES_DEFAULT=7
# 日志formatter,建议开发环境为line,生产环境为json,可选值为 Monolog\Formatter\JsonFormatter|Monolog\Formatter\LineFormatter
LOG_FORMATTER_CLASS=Monolog\Formatter\LineFormatter
LOG_FORMATTER_CLASS_DEFAULT=Monolog\Formatter\LineFormatter
LOG_FORMATTER_CLASS_SQL=Monolog\Formatter\LineFormatter
# stdout logger输出级别,如果要禁用其中一种或者几种,删除其中对应的级别即可
STDOUT_LOG_LEVEL=info,notice,warning,error,critical,alert,emergency
#---------------------------------启用定时任务start-----------------------------------------------------
CRONTAB_ENABLE=true
#---------------------------------定时任务end-----------------------------------------------------
#---------------------------------数据库start-----------------------------------------------------
DB_DRIVER=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=hyperf
DB_USERNAME=root
DB_PASSWORD=
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci
DB_PREFIX=
#品牌商
BRAND_DB_DRIVER=mysql
BRAND_DB_HOST=192.168.0.200
BRAND_DB_PORT=8306
BRAND_DB_DATABASE=ydd_brand_business
BRAND_DB_USERNAME=root
BRAND_DB_PASSWORD=gALC8Lmw3y
BRAND_DB_CHARSET=utf8mb4
BRAND_DB_COLLATION=utf8mb4_unicode_ci
BRAND_DB_PREFIX=ydd_
#---------------------------------防窜货数据库 start---------------------------------------------
DB_REIMBURSEMENT_DRIVER=mysql
DB_REIMBURSEMENT_HOST=192.168.0.200
DB_REIMBURSEMENT_DATABASE=ydd_reimbursement
DB_REIMBURSEMENT_PORT=8306
DB_REIMBURSEMENT_USERNAME=root
DB_REIMBURSEMENT_PASSWORD=gALC8Lmw3y
DB_REIMBURSEMENT_CHARSET=utf8mb4
DB_REIMBURSEMENT_COLLATION=utf8mb4_unicode_ci
DB_REIMBURSEMENT_PREFIX=ydd_
DB_REIMBURSEMENT_MAX_IDLE_TIME=60
#---------------------------------防窜货数据库 end-----------------------------------------------
#云店后台
CLOUD_DB_DRIVER=mysql
CLOUD_DB_HOST=192.168.0.200
CLOUD_DB_PORT=8306
CLOUD_DB_DATABASE=ydd_cloud_store
CLOUD_DB_USERNAME=root
CLOUD_DB_PASSWORD=gALC8Lmw3y
CLOUD_DB_CHARSET=utf8mb4
CLOUD_DB_COLLATION=utf8mb4_unicode_ci
CLOUD_DB_PREFIX=ydd_
# 营销
MARKETING_DB_DRIVER=mysql
MARKETING_DB_HOST=192.168.0.200
MARKETING_DB_PORT=8306
MARKETING_DB_DATABASE=ydd_marketing
MARKETING_DB_USERNAME=root
MARKETING_DB_PASSWORD=gALC8Lmw3y
MARKETING_DB_CHARSET=utf8mb4
MARKETING_DB_COLLATION=utf8mb4_unicode_ci
MARKETING_DB_PREFIX=ydd_
#消费者社区
DB_MEMBER_DRIVER=mysql
DB_MEMBER_HOST=192.168.0.200
DB_MEMBER_PORT=8306
DB_MEMBER_DATABASE=ydd_member
DB_MEMBER_USERNAME=root
DB_MEMBER_PASSWORD=gALC8Lmw3y
DB_MEMBER_CHARSET=utf8mb4
DB_MEMBER_COLLATION=utf8mb4_unicode_ci
DB_MEMBER_PREFIX=ydd_
#码库
CODE_DB_DRIVER=mysql
CODE_DB_HOST=192.168.0.200
CODE_DB_PORT=8306
CODE_DB_DATABASE=ydd_code
CODE_DB_USERNAME=root
CODE_DB_PASSWORD=gALC8Lmw3y
CODE_DB_CHARSET=utf8mb4
CODE_DB_COLLATION=utf8mb4_unicode_ci
CODE_DB_PREFIX=ydd_
#电商通
ECPASS_DB_DRIVER=mysql
ECPASS_DB_HOST=192.168.0.200
ECPASS_DB_PORT=8306
ECPASS_DB_DATABASE=ydd_ecpass
ECPASS_DB_USERNAME=root
ECPASS_DB_PASSWORD=gALC8Lmw3y
ECPASS_DB_CHARSET=utf8mb4
ECPASS_DB_COLLATION=utf8mb4_unicode_ci
ECPASS_DB_PREFIX=ydd_
#---------------------------------数据库end-----------------------------------------------------
REDIS_HOST=localhost
REDIS_AUTH=(null)
REDIS_PORT=6379
REDIS_DB=0
# ------------------- Guzzle配置 -------------------------------------------------------------------
GUZZLE_BRAND_BUSINESS_HOST = http://pps-api.test.2vm.co
# ------------------- Guzzle配置end ----------------------------------------------------------------
.buildpath
.settings/
.project
*.patch
.idea/
.git/
runtime/
vendor/
.phpintel/
.env
.DS_Store
.phpunit*
*.cache
composer.lock
.vscode/
\ No newline at end of file
stages:
- build
dev_build:
stage: build
script:
- ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${DEV_SSH_IP} "cd ${DEV_WEB_DIR} && pwd && git checkout . && git pull origin develop"
- ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${DEV_SSH_IP} "cd ${DEV_WEB_DIR} && pwd && docker exec -it ${DEV_PROJECT_NAME} sh -c 'supervisorctl stop all && supervisorctl start all'"
tags:
- dev-build
only:
- develop
uat_build:
stage: build
script:
- ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${UAT_SSH_IP} "cd ${UAT_WEB_DIR} && pwd && git checkout . && git pull origin uat"
- ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${UAT_SSH_IP} "echo ${UAT_PROJECT_NAME} && docker exec -it ${UAT_PROJECT_NAME} sh -c 'supervisorctl stop all && supervisorctl start all'"
tags:
- uat-build
only:
- uat
master_build:
stage: build
script:
- ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${MASTER_SSH_IP} "cd ${MASTER_WEB_DIR} && pwd && git checkout . && git pull origin master"
- ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${MASTER_SSH_IP} "cd ${YUNWEI_DIR} && pwd && ${ANSIBLE_COMMAND}"
tags:
- master-build
only:
- master
\ No newline at end of file
<?php
$header = <<<'EOF'
This file is part of Hyperf.
@link https://www.hyperf.io
@document https://hyperf.wiki
@contact group@hyperf.io
@license https://github.com/hyperf/hyperf/blob/master/LICENSE
EOF;
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@DoctrineAnnotation' => true,
'@PhpCsFixer' => true,
'header_comment' => [
'comment_type' => 'PHPDoc',
'header' => $header,
'separate' => 'none',
'location' => 'after_declare_strict',
],
'array_syntax' => [
'syntax' => 'short'
],
'list_syntax' => [
'syntax' => 'short'
],
'concat_space' => [
'spacing' => 'one'
],
'blank_line_before_statement' => [
'statements' => [
'declare',
],
],
'general_phpdoc_annotation_remove' => [
'annotations' => [
'author'
],
],
'ordered_imports' => [
'imports_order' => [
'class', 'function', 'const',
],
'sort_algorithm' => 'alpha',
],
'single_line_comment_style' => [
'comment_types' => [
],
],
'yoda_style' => [
'always_move_variable' => false,
'equal' => false,
'identical' => false,
],
'phpdoc_align' => [
'align' => 'left',
],
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'constant_case' => [
'case' => 'lower',
],
'class_attributes_separation' => true,
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'linebreak_after_opening_tag' => true,
'lowercase_static_reference' => true,
'no_useless_else' => true,
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'not_operator_with_space' => false,
'ordered_class_elements' => true,
'php_unit_strict' => false,
'phpdoc_separation' => false,
'single_quote' => true,
'standardize_not_equals' => true,
'multiline_comment_opening_closing' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('public')
->exclude('runtime')
->exclude('vendor')
->in(__DIR__)
)
->setUsingCache(false);
<?php
namespace PHPSTORM_META {
// Reflect
override(\Psr\Container\ContainerInterface::get(0), map('@'));
override(\Hyperf\Utils\Context::get(0), map('@'));
override(\make(0), map('@'));
override(\di(0), map('@'));
}
\ No newline at end of file
# Default Dockerfile
#
# @link https://www.hyperf.io
# @document https://hyperf.wiki
# @contact group@hyperf.io
# @license https://github.com/hyperf/hyperf/blob/master/LICENSE
FROM hyperf/hyperf:8.0-alpine-v3.12-swoole
LABEL maintainer="Hyperf Developers <group@hyperf.io>" version="1.0" license="MIT" app.name="Hyperf"
##
# ---------- env settings ----------
##
# --build-arg timezone=Asia/Shanghai
ARG timezone
ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
APP_ENV=prod \
SCAN_CACHEABLE=(true)
# update
RUN set -ex \
# show php version and extensions
&& php -v \
&& php -m \
&& php --ri swoole \
# ---------- some config ----------
&& cd /etc/php8 \
# - config PHP
&& { \
echo "upload_max_filesize=128M"; \
echo "post_max_size=128M"; \
echo "memory_limit=1G"; \
echo "date.timezone=${TIMEZONE}"; \
} | tee conf.d/99_overrides.ini \
# - config timezone
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& echo "${TIMEZONE}" > /etc/timezone \
# ---------- clear works ----------
&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
&& echo -e "\033[42;37m Build Completed :).\033[0m\n"
WORKDIR /opt/www
# Composer Cache
# COPY ./composer.* /opt/www/
# RUN composer install --no-dev --no-scripts
COPY . /opt/www
RUN composer install --no-dev -o && php bin/hyperf.php
EXPOSE 9501
ENTRYPOINT ["php", "/opt/www/bin/hyperf.php", "start"]
# Introduction
此项目为 xxl-job 的 php 执行器部分
运行环境: PHP8+ , hyperf/xxl-job-incubator": "v0.1.3
xxl-job-incubator: 为 v0.1.3 可以保证 hypref 框架为: ~2.2
\ No newline at end of file
差异被折叠。
<?php
declare(strict_types=1);
namespace App\Command;
use Carbon\Carbon;
use App\Model\Marketing\Scan;
use App\Task\ScanStatisticsTask;
use App\Task\ScanAwardStatisticsTask;
use Psr\Container\ContainerInterface;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Symfony\Component\Console\Input\InputOption;
/**
* @Command
*/
class ActivityStatistics extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
protected $signature = 'act:statistics {day? : day} {--brand_id= : brand_id}';
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct();
}
public function configure()
{
parent::configure();
$this->setDescription('活动统计');
}
public function handle()
{
$day = $this->input->getArgument('day');
$ScanStatisticsTask = make(ScanStatisticsTask::class);
$ScanAwardStatisticsTask = make(ScanAwardStatisticsTask::class);
// 品牌商
$brand_id = $this->input->getOption('brand_id');
if (!empty($brand_id)) {
$ScanStatisticsTask->setBrandId($brand_id);
$ScanAwardStatisticsTask->setBrandId($brand_id);
}
if( empty($day) ) {
$day = Carbon::yesterday('Asia/shanghai')->toDateString();
}
if( $day != 'all' ) {
$ScanStatisticsTask->setDateTime($day);
$ScanAwardStatisticsTask->setDateTime($day);
$this->line('活动扫码统计:' . $day, 'info');
$ScanStatisticsTask->execute();
$this->line('活动参与统计:' . $day, 'info');
$ScanAwardStatisticsTask->execute();
}
// 全数据更新
if( $day == 'all' ) {
if ( $brand_id ) {
$created_time = Scan::where('brand_id',$brand_id)->value('created_time');
} else {
$created_time = Scan::value('created_time');
}
$today = Carbon::today('Asia/shanghai')->toDateString();
$day = Carbon::parse($created_time)->toDateString();
do {
$ScanStatisticsTask->setDateTime($day);
$ScanAwardStatisticsTask->setDateTime($day);
$this->line('活动扫码统计:' . $day, 'info');
$ScanStatisticsTask->execute();
$this->line('活动参与统计:' . $day, 'info');
$ScanAwardStatisticsTask->execute();
# code...
$day = Carbon::parse($day)->addDay()->toDateString();
} while ($day < $today);
}
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use App\Task\ScanTotalStatisticsTask;
use Carbon\Carbon;
use App\Model\Marketing\Scan;
use App\Task\ScanStatisticsTask;
use App\Task\ScanAwardStatisticsTask;
use Psr\Container\ContainerInterface;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Symfony\Component\Console\Input\InputOption;
/**
* @Command
*/
class AllActivityStatistics extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
protected $signature = 'act:all_statistics {day? : day} {--brand_id= : brand_id}';
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct();
}
public function configure()
{
parent::configure();
$this->setDescription('活动统计');
}
public function handle()
{
$day = $this->input->getArgument('day');
$ScanTotalStatisticsTask = make(ScanTotalStatisticsTask::class);
// 品牌商
$brand_id = $this->input->getOption('brand_id');
if (!empty($brand_id)) {
$ScanTotalStatisticsTask->setBrandId($brand_id);
}
if( empty($day) ) {
$day = Carbon::yesterday('Asia/shanghai')->toDateString();
}
if( $day != 'all' ) {
$ScanTotalStatisticsTask->setDateTime($day);
$this->line('活动扫码总统计:' . $day, 'info');
$ScanTotalStatisticsTask->execute();
}
// 全数据更新
if( $day == 'all' ) {
if ( $brand_id ) {
$created_time = Scan::where('brand_id',$brand_id)->value('created_time');
} else {
$created_time = Scan::value('created_time');
}
$today = Carbon::today('Asia/shanghai')->toDateString();
$day = Carbon::parse($created_time)->toDateString();
do {
$ScanTotalStatisticsTask->setDateTime($day);
$this->line('活动扫码总统计:' . $day, 'info');
$ScanTotalStatisticsTask->execute();
# code...
$day = Carbon::parse($day)->addDay()->toDateString();
} while ($day < $today);
}
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Carbon\Carbon;
use App\Task\BrandConsumeTask;
use Hyperf\Command\Annotation\Command;
use App\Model\Brand\BrandSmallBillModel;
use Hyperf\Command\Command as HyperfCommand;
use Symfony\Component\Console\Input\InputArgument;
/**
* @Command
*/
class BrandConsumeCommand extends HyperfCommand
{
protected $name = 'run:BrandConsume';
public function configure()
{
parent::configure();
$this->setDescription('品牌商小额消费记录信息维护');
}
protected function getArguments()
{
return [
['day', InputArgument::OPTIONAL, '日期']
];
}
public function handle()
{
$day = $this->input->getArgument('day');
$BrandConsumeTask = (new BrandConsumeTask);
if ( $day == 'all' ) {
$days = BrandSmallBillModel::groupBy('day')->pluck('day')->toArray();
foreach ($days as $day) {
$this->line('统计账单'. $day );
$BrandConsumeTask->setDateTime($day)->execute();
}
} else if ( ! $day ) {
$day = Carbon::yesterday('Asia/shanghai')->toDateString();
$BrandConsumeTask->setDateTime($day)->execute();
$this->line('已执行!');
}
}
}
<?php
declare( strict_types=1 );
namespace App\Command;
use App\Model\Brand\PointSet;
use App\Repository\Member\MemberPointRepository;
use Psr\Container\ContainerInterface;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Symfony\Component\Console\Input\InputArgument;
/**
* @Command
*/
class ClearMemberPointCommand extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct( ContainerInterface $container )
{
$this->container = $container;
parent::__construct( 'clear:memberPoint' );
}
public function configure()
{
parent::configure();
$this->addUsage( 'clear:memberPoint' );
$this->setDescription( '会员积分清零' );
$this->addArgument( 'brand_id', InputArgument::OPTIONAL, '品牌商编号');
}
public function handle()
{
$brand_id = $this->input->getArgument('brand_id');
// 获取需要清理积分的品牌商
$query = PointSet::with('brand');
if($brand_id){
$query->where('brand_id',$brand_id);
}
$brands = $query->get();
// 过滤过期的品牌商
$time = time();
foreach ( $brands as $brand ) {
if ( $brand->brand->status == 1 && $brand->brand->signing_end_time > $time ) {
if($brand->point_is_clear == 2){
//清除所有积分(本定时任务是每年1月1日00:00:00 执行,清除的就是本年之前所有的积分)
$yester_year = date('Y-m-d H:i:s',strtotime(date('Y-01-01 00:00:00')));
}elseif($brand->point_is_clear == 1){
// 获取要清理的截取日期 当前 2023-01-01 00:00:00 获取 2022-01-01 00:00:00 积分保留一年
$yester_year = date('Y-m-d H:i:s',strtotime(date('Y-01-01 00:00:00',strtotime("-1 year"))));
}else{
continue;
}
MemberPointRepository::execSingleBrand( $brand->brand_id, $yester_year,$brand->point_is_clear );
}
}
$this->line('success' );
}
}
<?php
declare( strict_types=1 );
namespace App\Command;
use App\Task\CouponStatisticsTask;
use App\Model\Brand\CouponMemberLog;
use Psr\Container\ContainerInterface;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Symfony\Component\Console\Input\InputArgument;
/**
* 直播活动订阅消息推送
*
* @Command
*/
class CouponStatisticsCommand extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
/**
* 命令
*
* @var string
*/
protected $name = "coupon:statistics";
public function configure()
{
parent::configure();
$this->setDescription('Coupon statistics');
$this->addUsage('Demo:coupon:statistics 2021-11-13');
$this->addArgument('date', InputArgument::OPTIONAL, 'Need to count which date(all: means all statistics)', 'all');
$this->addArgument('end_date', InputArgument::OPTIONAL, 'If it is a specified date range, this parameter must be passed,demo:2021-11-13');
}
public function handle()
{
$task = make(CouponStatisticsTask::class);
$date =$this->input->getArgument('date');
$end_date = $this->input->getArgument('end_date');
//date=all,统计全部数据
if($date == 'all'){
//前一天的时间戳
$yes_time = time() - 86400;
$begin_time = CouponMemberLog::query()->orderBy('create_time')->value('create_time');
$date = date('Y-m-d', $begin_time);
do {
$task->setTime($date)->execute();
$begin_time = $begin_time + 86400;
$date = date('Y-m-d', $begin_time);
} while ($begin_time < $yes_time);
}elseif($date && $end_date){
//指定时间范围
$begin_time = strtotime($date);
$end_time = strtotime($end_date);
do {
$task->setTime($date)->execute();
$begin_time = $begin_time + 86400;
$date = date('Y-m-d', $begin_time);
} while ($begin_time <= $end_time);
}else{
//指定日期
$begin_time = strtotime($date);
if($begin_time > time()){
$this->error('统计实际必须小于今天');
}
$task->setTime($date)->execute();
}
$this->info('success');
}
}
<?php
declare( strict_types=1 );
namespace App\Command;
use App\Model\Brand\PointSet;
use App\Repository\Member\MemberPointRepository;
use Psr\Container\ContainerInterface;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Symfony\Component\Console\Input\InputArgument;
use App\Model\Brand\Product;
/**
* @Command
*/
class CreateProductInfo extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct( ContainerInterface $container )
{
$this->container = $container;
parent::__construct( 'CreateProductInfo' );
}
public function configure()
{
parent::configure();
$this->addUsage( 'CreateProductInfo' );
$this->setDescription( '数据构造' );
}
public function handle()
{
$allProduct = [
'1.MCS.MCS032' => 2,
'1.MCS.MCS036' => 6,
'1.MCS.MCS038' => 111,
'1.MCS.MCS047' => 4,
'1.MCS.MCS048' => 20,
'1.MCS.MCS050' => 62,
'1.MCS.MCS051' => 112,
'1.MCS.MCS053' => 1,
'1.MCS.MCS055' => 1,
'1.MCS.MCS077' => 6,
'1.MCS.MCS081' => 2,
'1.MCS.MCS091' => 3,
'1.MCS.MCS113' => 10,
'1.MCS.MCS127' => 2,
'1.MCS.MCS131' => 14,
'1.MCS.MCS132' => 102,
'1.MCS.MCS135' => 10,
'1.MCS.MCS141' => 2,
'1.MCS.MCS146' => 189,
'1.MCS.MCS155' => 10,
'1.MCS.MCS159' => 1,
'1.MCS.MCS001' => 360,
'1.MCS.MCS056' => 2,
'1.MCS.MCS511' => 6,
'1.MCS.MCS165' => 1,
'1.MCS.MCS166' => 1,
'1.MCS.MCS168' => 5,
];
$productList = Product::query()->where('brand_id', 10000534)->whereIn('product_sn', array_keys($allProduct))->select('id', 'product_sn', 'product_name')->get();
$insert = 'insert into ydd_reimbursement.ydd_fch_statistics_general_product_stock(brand_id, day, product_id, product_sn, warehouse_id, out_warehouse_num) values ';
foreach($productList as $product) {
$data = [
'brand_id' => 10000534,
'day' => 20250229,
'product_id' => $product->id,
'product_sn' => $product->product_sn,
'warehouse_id' => 1228,
'out_warehouse_num' => isset($allProduct[$product->product_sn]) ? $allProduct[$product->product_sn] : 0,
];
$insert .= "({$data['brand_id']}, {$data['day']}, {$data['product_id']}, '{$data['product_sn']}', {$data['warehouse_id']}, {$data['out_warehouse_num']}), \n";
}
echo $insert . "\n";
$this->line('success' );
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputArgument;
use App\Repository\Reimbursement\GeneralProductBatchStockStatisticsRepository;
use App\Model\Brand\Brand;
use Swoole\Coroutine as co;
/**
* @Command
*/
#[Command]
class GeneralProductBatchStockStatistics extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('statistics:GeneralProductBatchStock');
}
public function configure()
{
parent::configure();
$this->setDescription('总部商品批次库存统计数据统计');
$this->addArgument('day', InputArgument::REQUIRED, '开始时间:');
$this->addArgument('end_day', InputArgument::REQUIRED, '结束时间');
$this->addArgument( 'brand_id', InputArgument::OPTIONAL, '品牌商编号' );
}
public function handle()
{
$repository = new GeneralProductBatchStockStatisticsRepository();
$this->line('脚本开始执行', 'info');
$brand_id = $this->input->getArgument( 'brand_id' );
$day = $this->input->getArgument('day');
$end_day = $this->input->getArgument('end_day');
$query = Brand::query()->where('status', 1)
->select('brand_no');
if ($brand_id){
$query->where('brand_no',$brand_id);
}
$query->chunkById(100, function($brand) use($repository, $day, $end_day){
foreach($brand as $v){
$this->warn($v['brand_no']. ' 开始执行');
if ($day && $end_day) {
$date = $day;
//指定时间范围
$beginTime = strtotime($day);
$endTime = strtotime($end_day);
do {
if ($date > 0) {
$this->warn(' ' . $v['brand_no']. ' ' .$date);
$repository
->setBrandId($v['brand_no'])
->setTime($date)
->entry();
}
$beginTime = $beginTime + 86400;
$date = date('Ymd', $beginTime);
co::sleep(0.1); // 延时 0.1 秒
} while ($beginTime <= $endTime);
} else {
$this->warn(' ' . $day);
$repository
->setBrandId($v['brand_no'])
->setTime($day)
->entry();
}
}
}, 'brand_no');
$this->info('success');
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputArgument;
use App\Repository\Reimbursement\GeneralProductStockStatisticsRepository;
use App\Model\Brand\Brand;
use Swoole\Coroutine as co;
/**
* @Command
*/
#[Command]
class GeneralProductStockStatistics extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('statistics:GeneralProductStock');
}
public function configure()
{
parent::configure();
$this->setDescription('总部商品库存统计数据统计');
$this->addArgument('day', InputArgument::REQUIRED, '开始时间:');
$this->addArgument('end_day', InputArgument::REQUIRED, '结束时间');
$this->addArgument( 'brand_id', InputArgument::OPTIONAL, '品牌商编号' );
}
public function handle()
{
$repository = new GeneralProductStockStatisticsRepository();
$this->line('脚本开始执行', 'info');
$brand_id = $this->input->getArgument( 'brand_id' );
$day = $this->input->getArgument('day');
$end_day = $this->input->getArgument('end_day');
$query = Brand::query()->where('status', 1)
->select('brand_no');
if ($brand_id){
$query->where('brand_no',$brand_id);
}
$query->chunkById(100, function($brand) use($repository, $day, $end_day){
foreach($brand as $v){
$this->warn($v['brand_no']. ' 开始执行');
if ($day && $end_day) {
$date = $day;
//指定时间范围
$beginTime = strtotime($day);
$endTime = strtotime($end_day);
do {
if ($date > 0) {
$this->warn(' ' . $v['brand_no']. ' ' .$date);
$repository
->setBrandId($v['brand_no'])
->setTime($date)
->entry();
}
$beginTime = $beginTime + 86400;
$date = date('Ymd', $beginTime);
co::sleep(0.1); // 延时 0.1 秒
} while ($beginTime <= $endTime);
} else {
$this->warn(' ' . $day);
$repository
->setBrandId($v['brand_no'])
->setTime($day)
->entry();
}
}
}, 'brand_no');
$this->info('success');
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputArgument;
use App\Repository\Reimbursement\GeneralProductStockStatisticsYearRepository;
use App\Repository\Reimbursement\GeneralProductBatchStockStatisticsYearRepository;
use App\Repository\Reimbursement\GeneralProductWarehouseStockStatisticsYearRepository;
use App\Model\Brand\Brand;
use Swoole\Coroutine as co;
/**
* @Command
*/
#[Command]
class GeneralProductStockYearStatisticsSummary extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('statistics:GeneralProductStockYearSummary');
}
public function configure()
{
parent::configure();
$this->setDescription('总部商品库存统计数据统计-年度汇总');
$this->addArgument('year', InputArgument::REQUIRED, '年份:');
$this->addArgument( 'brand_id', InputArgument::OPTIONAL, '品牌商编号' );
}
public function handle()
{
$repository1 = new GeneralProductStockStatisticsYearRepository();
$repository2 = new GeneralProductBatchStockStatisticsYearRepository();
$repository3 = new GeneralProductWarehouseStockStatisticsYearRepository();
$this->line('脚本开始执行', 'info');
$brand_id = $this->input->getArgument( 'brand_id' );
$year = $this->input->getArgument('year');
$query = Brand::query()->where('status', 1)
->select('brand_no');
if ($brand_id){
$query->where('brand_no',$brand_id);
}
$query->chunkById(100, function($brand) use($repository1, $repository2, $repository3, $year){
foreach($brand as $v){
$this->warn($v['brand_no']. ' 开始执行');
$repository1
->setBrandId($v['brand_no'])
->setTime($year)
->entry();
$repository2
->setBrandId($v['brand_no'])
->setTime($year)
->entry();
$repository3
->setBrandId($v['brand_no'])
->setTime($year)
->entry();
co::sleep(0.1); // 延时 0.1 秒
}
}, 'brand_no');
$this->info('success');
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputArgument;
use App\Repository\Reimbursement\GeneralProductWarehouseStockStatisticsRepository;
use App\Model\Brand\Brand;
use Swoole\Coroutine as co;
/**
* @Command
*/
#[Command]
class GeneralProductWarehouseStatistics extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('statistics:GeneralProductWarehouseStatistics');
}
public function configure()
{
parent::configure();
$this->setDescription('总部商品仓库库存统计数据统计');
$this->addArgument('day', InputArgument::REQUIRED, '开始时间:');
$this->addArgument('end_day', InputArgument::REQUIRED, '结束时间');
$this->addArgument( 'brand_id', InputArgument::OPTIONAL, '品牌商编号' );
}
public function handle()
{
$repository = new GeneralProductWarehouseStockStatisticsRepository();
$this->line('脚本开始执行', 'info');
$brand_id = $this->input->getArgument( 'brand_id' );
$day = $this->input->getArgument('day');
$end_day = $this->input->getArgument('end_day');
$query = Brand::query()->where('status', 1)
->select('brand_no');
if ($brand_id){
$query->where('brand_no',$brand_id);
}
$query->chunkById(100, function($brand) use($repository, $day, $end_day){
foreach($brand as $v){
$this->warn($v['brand_no']. ' 开始执行');
if ($day && $end_day) {
$date = $day;
//指定时间范围
$beginTime = strtotime($day);
$endTime = strtotime($end_day);
do {
if ($date > 0) {
$this->warn(' ' . $v['brand_no']. ' ' .$date);
$repository
->setBrandId($v['brand_no'])
->setTime($date)
->entry();
}
$beginTime = $beginTime + 86400;
$date = date('Ymd', $beginTime);
co::sleep(0.1); // 延时 0.1 秒
} while ($beginTime <= $endTime);
} else {
$this->warn(' ' . $day);
$repository
->setBrandId($v['brand_no'])
->setTime($day)
->entry();
}
}
}, 'brand_no');
$this->info('success');
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Carbon\Carbon;
use App\Task\MemberVipExpireTask;
use Psr\Container\ContainerInterface;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Symfony\Component\Console\Input\InputOption;
/**
* @Command
*/
class MemberVipExpireCommand extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
protected $signature = 'user:expire_time {--brand_id= : brand_id}';
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct();
}
public function configure()
{
parent::configure();
$this->setDescription('会员到期');
}
public function handle()
{
$task = make(MemberVipExpireTask::class);
// 品牌商
$brand_id = $this->input->getOption('brand_id');
if (!empty($brand_id)) {
$task->setBrandId($brand_id);
}
$task->execute();
$this->line('已执行!');
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputArgument;
use App\Repository\Reimbursement\OutWarehouseStatisticsRepository;
use Carbon\Carbon;
use App\Model\Brand\Brand;
use Swoole\Coroutine as co;
/**
* @Command
*/
#[Command]
class OutWarehouseStatistics extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('statistics:outwarehouse');
}
public function configure()
{
parent::configure();
$this->setDescription('出库数据统计');
$this->addArgument('day', InputArgument::REQUIRED, '开始时间:');
$this->addArgument('end_day', InputArgument::REQUIRED, '结束时间');
$this->addArgument( 'brand_id', InputArgument::OPTIONAL, '品牌商编号' );
}
public function handle()
{
$repository = new OutWarehouseStatisticsRepository();
$this->line('脚本开始执行', 'info');
$day = $this->input->getArgument('day');
$end_day = $this->input->getArgument('end_day');
$brand_id = $this->input->getArgument( 'brand_id' );
$query = Brand::query()->where('status', 1)
->select('brand_no');
if($brand_id){
$query->where('brand_no', $brand_id);
}
$query->chunkById(100, function($brand) use($day, $end_day, $repository){
foreach($brand as $v){
$this->warn($v['brand_no']. ' 开始执行');
set_auth_brand_id($v['brand_no']);
if ($day && $end_day) {
$date = $day;
//指定时间范围
$beginTime = strtotime($day);
$endTime = strtotime($end_day);
do {
if ($date > 0) {
$this->warn(' ' . $v['brand_no'] . ' '. $date);
$repository
->setBrandId($v['brand_no'])
->setTime($date)
->entry();
}
$beginTime = $beginTime + 86400;
$date = date('Ymd', $beginTime);
co::sleep(0.1); // 延时 0.1 秒
} while ($beginTime <= $endTime);
} else {
$this->warn(' ' . $day);
$repository
->setBrandId($v['brand_no'])
->setTime($day)
->entry();
}
}
}, 'brand_no');
$this->info('success');
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputArgument;
use App\Repository\Reimbursement\RefundWarehouseStatisticsRepository;
use Carbon\Carbon;
use App\Model\Brand\Brand;
use Swoole\Coroutine as co;
/**
* @Command
*/
#[Command]
class RefundWarehouseStatistics extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('statistics:refundwarehouse');
}
public function configure()
{
parent::configure();
$this->setDescription('退货数据统计');
$this->addArgument( 'start_time', InputArgument::REQUIRED, '开始时间Y-m-d' );
$this->addArgument( 'end_time', InputArgument::REQUIRED, '结束时间Y-m-d' );
$this->addArgument( 'brand_id', InputArgument::OPTIONAL, '品牌商编号' );
}
public function handle()
{
$repository = new RefundWarehouseStatisticsRepository();
$this->line('脚本开始执行', 'info');
$start_day = $this->input->getArgument( 'start_time' );
$end_day = $this->input->getArgument( 'end_time' );
$brand_id = $this->input->getArgument( 'brand_id' );
$start_time = Carbon::parse( $start_day )->startOfDay()->toDateTimeString();
$end_time = Carbon::parse( $end_day )->endOfDay()->toDateTimeString();
$query = Brand::query()->where('status', 1)
->select('brand_no');
if($brand_id){
$query->where('brand_no',$brand_id);
}
$query->chunkById(100, function($brand) use($start_time, $end_time, $repository){
foreach($brand as $v){
$this->warn($v['brand_no']. ' 开始执行');
set_auth_brand_id($v['brand_no']);
$repository
->setBrandId($v['brand_no'])
->setTime($start_time, $end_time)
->entry();
co::sleep(0.1); // 延时 0.1 秒
}
}, 'brand_no');
$this->info('success');
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Carbon\Carbon;
use Hyperf\DbConnection\Db;
use App\Task\PointClearTask;
use App\Model\Marketing\Scan;
use App\Task\ScanStatisticsTask;
use App\Task\UserTagAutoSetTask;
use App\Task\ScanAwardStatisticsTask;
use Psr\Container\ContainerInterface;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use App\Model\Marketing\StatisticsScanProvince;
/**
* @Command
* 执行 数据修复
*/
class RunDebugData extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
// php -d memory_limit=-1 bin/hyperf.php run_debug
protected $signature = 'run_debug';
protected $brand_id = null;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct();
}
public function configure()
{
parent::configure();
$this->setDescription('执行 定时任务的调用');
}
public function handle()
{
$start = '2023-01-01';
do {
$this->line( date('H:i:s') .' -- ' . $start , 'info');
self::rubn( $start );
$start = Carbon::parse( $start )->addDay()->format('Y-m-d');
$day = Carbon::parse( $start )->format('Ymd');
} while ($day < 20231209);
$this->line('任务运行结束!', 'info');
}
public static function rubn( $date_time)
{
$day = Carbon::parse( $date_time )->format('Ymd');
$scan = Scan::query();
// 省级数据统计
$scan->where('day', $day)
->groupBy('brand_id', 'province_id', 'product_id', 'activity_id')
->select(
'brand_id',
'product_id',
'activity_id',
'province_id',
'province',
Db::raw('count(*) as scan_total'),
Db::raw("count(distinct(product_code)) as scan_number"),
Db::raw("count(if(is_first=1,true,null)) as first_scan_num"),
Db::raw("count(if(is_first=0,true,null)) as repeat_scan_num")
)
->chunk(100, function ($list) use ($date_time) {
$created_time = Carbon::now('Asia/shanghai')->toDateTimeString();
foreach ($list as $item) {
$where = [
'date_time' => $date_time,
'brand_id' => $item->brand_id,
'product_id' => $item->product_id ?: 0,
'activity_id' => $item->activity_id ?: 0,
'province_id' => $item->province_id ?: 0,
];
$scan = [
'province' => $item->province,
'scan_total' => $item->scan_total ?? 0,
'scan_number' => $item->scan_number ?? 0,
'first_scan_num' => $item->first_scan_num ?? 0,
'repeat_scan_num' => $item->repeat_scan_num ?? 0,
'created_time' => $created_time
];
StatisticsScanProvince::updateOrInsert($where, $scan);
}
});
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Carbon\Carbon;
use Hyperf\DbConnection\Db;
use App\Task\PointClearTask;
use App\Model\Marketing\Scan;
use App\Task\ScanStatisticsTask;
use App\Task\UserTagAutoSetTask;
use App\Task\ScanAwardStatisticsTask;
use Psr\Container\ContainerInterface;
use Hyperf\Command\Annotation\Command;
use App\Model\Marketing\StatisticsScanCity;
use Hyperf\Command\Command as HyperfCommand;
/**
* @Command
* 执行 数据修复
*/
class RunDebugDataCity extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
// php -d memory_limit=-1 bin/hyperf.php run_debug_city
protected $signature = 'run_debug_city';
protected $brand_id = null;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct();
}
public function configure()
{
parent::configure();
$this->setDescription('执行 定时任务的调用');
}
public function handle()
{
$start = '2023-01-01';
do {
$this->line( date('H:i:s') .' -- ' . $start , 'info');
self::rubn( $start );
$start = Carbon::parse( $start )->addDay()->format('Y-m-d');
$day = Carbon::parse( $start )->format('Ymd');
} while ($day < 20231209);
$this->line('任务运行结束!', 'info');
}
public static function rubn( $date_time )
{
$day = Carbon::parse( $date_time )->format('Ymd');
$scan = Scan::query();
// 市级数据统计
$scan->where('day', $day)
->groupBy('brand_id', 'city_id', 'product_id', 'activity_id')
->select(
'brand_id',
'product_id',
'activity_id',
'province_id',
'city_id',
'province',
'city',
Db::raw('count(*) as scan_total'),
Db::raw("count(distinct(product_code)) as scan_number"),
Db::raw("count(if(is_first=1,true,null)) as first_scan_num"),
Db::raw("count(if(is_first=0,true,null)) as repeat_scan_num")
)
->chunk(100, function ($list) use ($date_time) {
foreach ($list as $item) {
$where = [
'date_time' => $date_time,
'brand_id' => $item->brand_id,
'product_id' => $item->product_id ?: 0,
'activity_id' => $item->activity_id ?: 0,
'province_id' => $item->province_id ?: 0,
'city_id' => $item->city_id ?: 0,
];
$scan = [
'province' => $item->province,
'city' => $item->city,
'scan_total' => $item->scan_total ?? 0,
'scan_number' => $item->scan_number ?? 0,
'first_scan_num' => $item->first_scan_num ?? 0,
'repeat_scan_num' => $item->repeat_scan_num ?? 0
];
StatisticsScanCity::updateOrInsert($where, $scan);
}
});
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Carbon\Carbon;
use Hyperf\DbConnection\Db;
use App\Task\PointClearTask;
use App\Model\Marketing\Scan;
use App\Task\ScanStatisticsTask;
use App\Task\UserTagAutoSetTask;
use App\Task\ScanAwardStatisticsTask;
use Psr\Container\ContainerInterface;
use Hyperf\Command\Annotation\Command;
use App\Model\Marketing\StatisticsScanCity;
use Hyperf\Command\Command as HyperfCommand;
use App\Model\Marketing\StatisticsScanDistrict;
/**
* @Command
* 执行 数据修复
*/
class RunDebugDataDistrict extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
// php -d memory_limit=-1 bin/hyperf.php run_debug_district
protected $signature = 'run_debug_district';
protected $brand_id = null;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct();
}
public function configure()
{
parent::configure();
$this->setDescription('执行 定时任务的调用');
}
public function handle()
{
$start = '2023-01-01';
do {
$this->line( date('H:i:s') .' -- ' . $start , 'info');
self::rubn( $start );
$start = Carbon::parse( $start )->addDay()->format('Y-m-d');
$day = Carbon::parse( $start )->format('Ymd');
} while ($day < 20231209);
$this->line('任务运行结束!', 'info');
}
public static function rubn( $date_time )
{
$day = Carbon::parse( $date_time )->format('Ymd');
$scan = Scan::query();
// 区级数据统计
$scan->where('day', $day)
->groupBy('brand_id', 'district_id', 'product_id', 'activity_id')
->select(
'brand_id',
'product_id',
'activity_id',
'province_id',
'city_id',
'district_id',
'province',
'city',
'district',
Db::raw('count(*) as scan_total'),
Db::raw("count(distinct(product_code)) as scan_number"),
Db::raw("count(if(is_first=1,true,null)) as first_scan_num"),
Db::raw("count(if(is_first=0,true,null)) as repeat_scan_num")
)
->chunk(100, function ($list) use ($date_time) {
foreach ($list as $item) {
$where = [
'date_time' => $date_time,
'brand_id' => $item->brand_id,
'product_id' => $item->product_id ?: 0,
'activity_id' => $item->activity_id ?: 0,
'province_id' => $item->province_id ?: 0,
'city_id' => $item->city_id ?: 0,
'district_id' => $item->district_id ?: 0,
];
$scan = [
'province' => $item->province ?: '',
'city' => $item->city ?: '',
'district' => $item->district ?: '',
'scan_total' => $item->scan_total ?? 0,
'scan_number' => $item->scan_number ?? 0,
'first_scan_num' => $item->first_scan_num ?? 0,
'repeat_scan_num' => $item->repeat_scan_num ?? 0
];
StatisticsScanDistrict::updateOrInsert($where, $scan);
}
});
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use App\Task\BreSyncCodeBymTask;
use App\Task\PointClearTask;
use App\Task\UserTagAutoSetTask;
use App\Task\ScanAwardStatisticsTask;
use Psr\Container\ContainerInterface;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
/**
* @Command
* 执行 任务调用
*/
class RunTaskCommand extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
protected $signature = 'run:task {task : task} {brand_id? : brand_id}';
protected $brand_id = null;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct();
}
public function configure()
{
parent::configure();
$this->setDescription('执行 定时任务的调用');
}
public function handle()
{
// 品牌商
$task = $this->input->getArgument('task');
$tasks = [
'point_clear' => PointClearTask::class, // 积分清理任务
'user_tag_auto_set' => UserTagAutoSetTask::class, // 会员打标签
'scan_award_task' => ScanAwardStatisticsTask::class, // 奖项统计
'bre_code_sync' => BreSyncCodeBymTask::class, // 泊然恩同步贝因美码数据
];
if ( !isset( $tasks[ $task ]) ) {
return $this->error('不存此任务!');
}
$taskModel = make( $tasks[ $task ] )->setDateTime( '2023-11-12' );
if($tasks[ $task ]=='bre_code_sync'){
$brand_id = $this->input->getArgument('brand_id');
if($brand_id){
$taskModel->setBrandId($brand_id);
}
}
$taskModel->execute();
$this->line('任务运行结束!', 'info');
}
}
<?php
declare( strict_types=1 );
namespace App\Command;
use App\Constants\ErrorCode;
use App\Exception\BusinessException;
use App\Model\Brand\SmsGroupSendDetail;
use App\Model\Brand\SmsSendHistory;
use App\Model\Brand\SmsStatistics;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;
use Hyperf\DbConnection\Db;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
/**
* @Command
*/
class SmsStatisticsCommand extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct( ContainerInterface $container )
{
$this->container = $container;
parent::__construct( 'statistics:sms' );
}
public function configure()
{
parent::configure();
$this->addUsage( 'statistics:sms --all' );
$this->setDescription( '短信统计,默认统计昨天的数据' );
$this->addOption( 'all', 'a', InputOption::VALUE_NONE, '是否重新统计所有数据' );
}
protected function getArguments()
{
return [
[ 'date', InputArgument::OPTIONAL, '所要统计的日期' ],
[ 'brand_id', InputArgument::OPTIONAL, '所要统计的品牌商,不传默认统计全部' ],
];
}
public function handle()
{
try {
$date = $this->input->getArgument( 'date' );
$brandId = $this->input->getArgument( 'brand_id' ) ?? 0;
$all = $this->input->getOption( 'all' );
// 从 $input 获取 name 参数
$yesterday = $date ?? date( 'Y-m-d', strtotime( "-1 day" ) );
if ( strtotime( $yesterday ) !== FALSE ) {
//统计昨天所有积分
if ( !$all ) {
$info = SmsStatistics::query()->whereDate( 'date', $yesterday )->first();
if ( $info ) {
throw new BusinessException( 10086, '已存在当天统计数据!' );
}
}
$handel = SmsSendHistory::query();
if ( !$all ) {
$handel->whereRaw( 'from_unixtime(create_time,"%Y-%m-%d") = "' . $yesterday . '"' );
}
if ( $brandId ) {
$handel->where( 'brand_id', $brandId );
}
$result = $handel->selectRaw( 'from_unixtime(create_time,"%Y-%m-%d") as date,brand_id,count(id) as ordinary_number_sent' )
->where( 'status', 2 )
->groupBy( [ 'brand_id', 'date' ] )
->get()
->toArray();
$handel1 = SmsGroupSendDetail::query();
if ( !$all ) {
$handel1->whereRaw( 'date_format(create_time,"%Y-%m-%d") = "' . $yesterday . '"' );
}
if ( $brandId ) {
$handel1->where( 'brand_id', $brandId );
}
$result2 = $handel1->selectRaw( 'date_format(create_time,"%Y-%m-%d") as date,brand_id,count(id) as group_number_sent' )
->where( 'status', 1 )
->groupBy( [ 'brand_id', 'date' ] )
->get()
->toArray();
$data = [];
if ( $result ) {
foreach ( $result as $value ) {
$data[ $value[ 'brand_id' ] ][ $value[ 'date' ] ][ 'ordinary_number_sent' ] = $value[ 'ordinary_number_sent' ];
}
}
if ( $result2 ) {
foreach ( $result2 as $value ) {
$data[ $value[ 'brand_id' ] ][ $value[ 'date' ] ][ 'group_number_sent' ] = $value[ 'group_number_sent' ];
}
}
$insert = [];
foreach ( $data as $d_brandId => $value ) {
foreach ( $value as $s_date => $v ) {
$insert[] = [
'brand_id' => $d_brandId,
'date' => $s_date,
'ordinary_number_sent' => $v[ 'ordinary_number_sent' ] ?? 0,
'group_number_sent' => $v[ 'group_number_sent' ] ?? 0,
];
}
}
if ( $insert ) {
SmsStatistics::insert( $insert );
}
$this->line( date( 'Y-m-d H:i:s', time() ) . "短信统计处理完成", 'info' );
} else {
throw new BusinessException( 10086, '时间格式错误!' );
}
} catch ( \Throwable $exception ) {
$this->line( date( 'Y-m-d H:i:s', time() ) . "短信统计处理异常:" . $exception->getMessage(), 'info' );
}
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use App\Task\VoucherStatusTask;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
/**
* @Command
*/
class VoucherStatusCommand extends HyperfCommand
{
protected $signature = 'run:VoucherStatus';
public function configure()
{
parent::configure();
$this->setDescription('提货卷状态信息维护');
}
public function handle()
{
(new VoucherStatusTask)->execute();
$this->line('已执行!');
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputArgument;
use App\Repository\Reimbursement\WarehouseStatisticsRepository;
use Carbon\Carbon;
use App\Model\Brand\Brand;
use Swoole\Coroutine as co;
/**
* @Command
*/
#[Command]
class WarehouseStatistics extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('statistics:warehouse');
}
public function configure()
{
parent::configure();
$this->setDescription('入库数据统计');
$this->addArgument('day', InputArgument::REQUIRED, '开始时间:');
$this->addArgument('end_day', InputArgument::REQUIRED, '结束时间');
$this->addArgument( 'brand_id', InputArgument::OPTIONAL, '品牌商编号' );
}
public function handle()
{
$repository = new WarehouseStatisticsRepository();
$this->line('脚本开始执行', 'info');
$day = $this->input->getArgument('day');
$end_day = $this->input->getArgument('end_day');
$brand_id = $this->input->getArgument( 'brand_id' );
$query = Brand::query()->where('status', 1)
->select('brand_no');
if($brand_id){
$query->where('brand_no',$brand_id);
}
$query->chunkById(100, function($brand) use($day, $end_day, $repository){
foreach($brand as $v){
$this->warn($v['brand_no']. ' 开始执行');
set_auth_brand_id($v['brand_no']);
if ($day && $end_day) {
$date = $day;
//指定时间范围
$beginTime = strtotime($day);
$endTime = strtotime($end_day);
do {
if ($date > 0) {
$this->warn(' ' . $v['brand_no'] . ' '. $date);
$repository
->setBrandId($v['brand_no'])
->setTime($date)
->entry();
}
$beginTime = $beginTime + 86400;
$date = date('Ymd', $beginTime);
co::sleep(0.1); // 延时 0.1 秒
} while ($beginTime <= $endTime);
} else {
$this->warn(' ' . $day);
$repository
->setBrandId($v['brand_no'])
->setTime($day)
->entry();
}
}
}, 'brand_no');
$this->info('success');
}
}
<?php
declare( strict_types=1 );
namespace App\Constants\Cache;
abstract class BaseAbstract
{
protected static function getPrefix( $brand_id )
{
return "ydd:" . $brand_id;
}
}
<?php
declare( strict_types=1 );
namespace App\Constants\Cache;
use Hyperf\Constants\Annotation\Constants;
/**
* @Constants
* Class ErrorCode
* @package App\Constants
*/
class CacheDatabaseConstants
{
/** @var string 默认 */
public const DEFAULT = 'default';
/**
* @Message('订单缓存')
*/
public const ORDER = 'order';
/**
* @Message('活动缓存')
*/
public const ACTIVITY = 'activity';
/**
* @Message('分表数据')
*/
public const SHARDING = 'sharding';
}
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Constants;
use Hyperf\Constants\AbstractConstants;
use Hyperf\Constants\Annotation\Constants;
/**
* @Constants
*/
class ErrorCode extends AbstractConstants
{
/**
* @Message("Server Error!")
*/
public const SERVER_ERROR = 500;
}
<?php
declare( strict_types=1 );
namespace App\Context;
use App\Constants\ErrorCode;
use App\Exception\BusinessException;
class BrandAuth
{
/**
* @var Model
*/
protected $user;
public function __construct( $user )
{
$this->user = $user;
}
/**
* 获取品牌商ID
*
* @return int
*/
public function brandId()
{
if (!is_null( $this->user)) {
if (isset($this->user['brand_id'])) {
return $this->user['brand_id'];
}
}
throw new BusinessException( ErrorCode::SERVER_ERROR, "登录失效,请重新登录!" );
}
}
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Controller;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Psr\Container\ContainerInterface;
abstract class AbstractController
{
/**
* @Inject
* @var ContainerInterface
*/
protected $container;
/**
* @Inject
* @var RequestInterface
*/
protected $request;
/**
* @Inject
* @var ResponseInterface
*/
protected $response;
}
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Controller;
use App\Task\ScanTotalStatisticsTask;
class IndexController extends AbstractController
{
public function index()
{
//make(ScanTotalStatisticsTask::class)->execute();
}
}
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Exception;
use App\Constants\ErrorCode;
use Hyperf\Server\Exception\ServerException;
use Throwable;
class BusinessException extends ServerException
{
public function __construct(int $code = 0, string $message = null, Throwable $previous = null)
{
if (is_null($message)) {
$message = ErrorCode::getMessage($code);
}
parent::__construct($message, $code, $previous);
}
}
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Exception\Handler;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Psr\Http\Message\ResponseInterface;
use Throwable;
class AppExceptionHandler extends ExceptionHandler
{
/**
* @var StdoutLoggerInterface
*/
protected $logger;
public function __construct(StdoutLoggerInterface $logger)
{
$this->logger = $logger;
}
public function handle(Throwable $throwable, ResponseInterface $response)
{
$this->logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile()));
$this->logger->error($throwable->getTraceAsString());
return $response->withHeader('Server', 'Hyperf')->withStatus(500)->withBody(new SwooleStream('Internal Server Error.'));
}
public function isValid(Throwable $throwable): bool
{
return true;
}
}
<?php
namespace App\Job;
use Hyperf\Di\Annotation\Inject;
use Hyperf\XxlJob\Annotation\XxlJob;
use Hyperf\XxlJob\Logger\JobExecutorLoggerInterface;
use Hyperf\XxlJob\Requests\RunRequest;
use Swoole\Process;
class DemoJob
{
#[Inject]
protected JobExecutorLoggerInterface $jobExecutorLogger;
/**
* 1.任务示例.
*/
#[XxlJob('demoJobHandler')]
public function demoJobHandler(RunRequest $request)
{
//获取参数
$params = $request->getExecutorParams();
//获取logId
$logId = $request->getLogId();
$this->jobExecutorLogger->info('params:' . $params);
for ($i = 1; $i < 5; ++$i) {
sleep(2);
$this->jobExecutorLogger->info($i);
$this->jobExecutorLogger->info('logId:' . $logId);
$this->jobExecutorLogger->info('params:' . $params);
}
}
/**
* 2、分片广播任务
*/
#[XxlJob('shardingJobHandler')]
public function shardingJobHandler(RunRequest $request)
{
// 分片参数
$shardIndex = $request->getBroadcastIndex();
$shardTotal = $request->getBroadcastTotal();
$this->jobExecutorLogger->info(sprintf('分片参数:当前分片序号 = %d, 总分片数 = %d', $shardIndex, $shardTotal));
// 业务逻辑
for ($i = 0; $i < $shardTotal; ++$i) {
if ($i == $shardIndex) {
$this->jobExecutorLogger->info('第 %d 片, 命中分片开始处理', $i);
} else {
$this->jobExecutorLogger->info('第 %d 片, 忽略', $i);
}
}
}
/**
* 3、执行命令.
*/
#[XxlJob('commandJobHandler')]
public function commandJobHandler(RunRequest $request)
{
//获取参数
//例子:php -v
$command = $request->getExecutorParams();
$result = shell_exec($command);
$message = str_replace("\n", '<br>', $result);
$this->jobExecutorLogger->info($message);
}
/**
* 4、param任务
* 参数示例:
* "url: http://www.baidu.com\n" +
* "method: get".
*/
#[XxlJob('paramJobHandler')]
public function paramJobHandler(RunRequest $request)
{
$param = $request->getExecutorParams();
$array = explode(PHP_EOL, $param);
/** array(2) {
[0]=>
string(25) "url: http://www.baidu.com"
[1]=>
string(11) "method: get"
}
*/
var_dump($param, $array);
}
/**
* 5、任务示例:任务初始化与销毁时,支持自定义相关逻辑.
*/
#[XxlJob(value: 'demoJob', init: 'initMethod', destroy: 'destroyMethod')]
public function demoJob()
{
$this->jobExecutorLogger->info('demoJob run...');
}
public function initMethod()
{
$this->jobExecutorLogger->info('initMethod');
}
public function destroyMethod()
{
$this->jobExecutorLogger->info('destroyMethod');
}
}
\ No newline at end of file
<?php
namespace App\Job;
use Hyperf\Di\Annotation\Inject;
use Hyperf\XxlJob\Annotation\XxlJob;
use Hyperf\XxlJob\Handler\AbstractJobHandler;
use Hyperf\XxlJob\Logger\JobExecutorLoggerInterface;
use Hyperf\XxlJob\Requests\RunRequest;
use App\Model\Brand\PointSet;
#[XxlJob("demoJobClassHandler")]
class DemoJobClass extends AbstractJobHandler
{
#[Inject]
protected JobExecutorLoggerInterface $jobExecutorLogger;
/**
* 执行任务
*/
public function execute(RunRequest $request): void
{
// 获取参数
$params = $request->getExecutorParams();
// 获取 LogId
$logId = $request->getLogId();
$brand_id = $params ?? 0;
// 获取需要清理积分的品牌商
$query = PointSet::with('brand');
if($brand_id){
$query->where('brand_id',$brand_id);
}
$brands = $query->get();
// 过滤过期的品牌商
$time = time();
foreach ( $brands as $brand ) {
$data = [
'brand_name' => $brand['brand']['brand_name'] ?? '',
'consume_explain' => $brand['consume_explain'],
'obtain_point' => $brand['obtain_point']
];
$this->jobExecutorLogger->info('brandInfo:' . json_encode($data, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE));
}
$this->jobExecutorLogger->info('logId:' . $logId);
$this->jobExecutorLogger->info('params:' . $params);
$this->jobExecutorLogger->info('success');
}
}
差异被折叠。
<?php
declare( strict_types=1 );
namespace App\Kernel\TreasureActivity;
use App\Cache\TreasureCache;
use Psr\Log\LoggerInterface;
use Hyperf\Logger\LoggerFactory;
use App\Model\Cloud\TreasureActivity;
class TreasureCacheHandle
{
/**
* @var TreasureCache
*/
protected $cache;
/**
* @var LoggerInterface
*/
private $logger;
public function __construct()
{
$this->logger = di( LoggerFactory::class )->get( 'treasure_cache', 'activity' );
$this->cache = new TreasureCache();
}
public function setActListCache( $brand_id )
{
$ids = TreasureActivity::query()
->where( 'brand_id', $brand_id )
->where( 'act_status', 1 )
->where( 'end_time', '>', time() )
->orderBy( 'start_time' )
->limit( 20 )
->pluck( 'id' )
->toArray();
$this->cache->setActListCache( $brand_id, $ids );
}
public function delActCache( $params )
{
try {
//只删除结束1天后的活动数据
$nowTime = time();
if ( $params['end_time'] < $nowTime && bcsub( (string) $nowTime, (string) $params['end_time'], 0 ) <= 24 * 3600 ) {
$this->logger->info( "活动结束不到一天,暂不删除!", $params );
return;
}
$this->cache->delCache( $params['brand_id'],$params['act_id'] );
return;
} catch ( \Throwable $exception ) {
$this->logger->error( "活动删除缓存异常!", [
$params,
$exception->getMessage(),
$exception->getTrace()
] );
return;
}
}
}
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Listener;
use Hyperf\Database\Events\QueryExecuted;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Logger\LoggerFactory;
use Hyperf\Utils\Arr;
use Hyperf\Utils\Str;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
/**
* Listener
*/
class DbQueryExecutedListener implements ListenerInterface
{
/**
* @var LoggerInterface
*/
private $logger;
public function __construct(ContainerInterface $container)
{
$this->logger = $container->get(LoggerFactory::class)->get('sql','sql');
}
public function listen(): array
{
return [
QueryExecuted::class,
];
}
/**
* @param QueryExecuted $event
*/
public function process(object $event)
{
if ($event instanceof QueryExecuted) {
$sql = $event->sql;
if (! Arr::isAssoc($event->bindings)) {
foreach ($event->bindings as $key => $value) {
$sql = Str::replaceFirst('?', "'{$value}'", $sql);
}
}
$this->logger->info(sprintf('[%s] %s', $event->time, $sql));
}
}
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class BonusCountModel extends Model
{
/**
* The connection name for the model.
*
* @var string
*/
protected $connection = 'brand';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'bonus_count';
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class BonusCountStatisticsModel extends Model
{
/**
* The connection name for the model.
*
* @var string
*/
protected $connection = 'brand';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'bonus_count_statistics';
// 黑名单字段
protected $guarded = [];
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class Brand extends Model
{
use SoftDeletes;
protected $connection = 'brand';
protected $table = 'brand';
protected $hidden = [ 'password' ];
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
protected $casts = [
'member_vip_card_config' => 'json',
];
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class BrandBillModel extends Model
{
/**
* The connection name for the model.
*
* @var string
*/
protected $connection = 'brand';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'brand_bill';
const TYPE_TEXTS = [
self::TYPE_REPLACE_BONUS => "代发红包",
];
const TYPE_REPLACE_BONUS = "replace_bonus"; // 代发红包
public function getTypeTextAttribute()
{
return self::TYPE_TEXTS[ $this->type ] ?? "异常分类";
}
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class BrandSmallBillModel extends Model
{
/**
* The connection name for the model.
*
* @var string
*/
protected $connection = 'brand';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'brand_small_bill';
const TYPE_TEXTS = [
self::TYPE_REPLACE_BONUS => "代发红包",
];
const TYPE_REPLACE_BONUS = "replace_bonus"; // 代发红包
public function getTypeTextAttribute()
{
return self::TYPE_TEXTS[ $this->type ] ?? "异常分类";
}
}
<?php
declare(strict_types=1);
namespace App\Model\Brand;
use App\Model\Model;
class CouponChannelStatistics extends Model
{
protected $connection = 'brand';
protected $table = 'coupon_channel_statistics';
protected $guarded = [];
const CREATED_AT = 'create_time';
const UPDATED_AT = null;
}
<?php
declare(strict_types=1);
namespace App\Model\Brand;
use App\Model\Model;
class CouponMemberLog extends Model
{
protected $connection = 'brand';
protected $table = 'coupon_member_log';
protected $guarded = [];
}
<?php
declare(strict_types=1);
namespace App\Model\Brand;
use App\Model\Model;
class CouponStoreStatistics extends Model
{
protected $connection = 'brand';
protected $table = 'coupon_store_statistics';
protected $guarded = [];
const CREATED_AT = 'create_time';
const UPDATED_AT = null;
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class Dealer extends Model
{
use SoftDeletes;
protected $connection = 'brand';
protected $table = 'dealer';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
}
\ No newline at end of file
<?php
declare(strict_types=1);
namespace App\Model\Brand;
use App\Model\Model;
class ExportLog extends Model
{
protected $connection = 'brand';
protected $table = 'export_log';
/** @var int 优惠券发放明细*/
const TYPE_COUPON_SEND = 1;
/** @var int 优惠券使用明细*/
const TYPE_COUPON_USE = 2;
/** @var array 应用对应模块:品牌 */
const APPLICATION_BRAND = [
self::TYPE_COUPON_SEND,
self::TYPE_COUPON_USE
];
/** @var array 应用对应模块:二维码管理 */
const APPLICATION_QRCODE = [];
/** @var array 应用对应模块:智能营销管理 */
const APPLICATION_SMART_MARKETING = [];
/** @var array 应用对应模块:智能防窜管理 */
const APPLICATION_AUTI_SMUGGLING = [];
/** @var array 应用对应模块:直播云店管理 */
const APPLICATION_LIVE_CLOUD_STORE = [];
/** @var array 具体数据类型 */
const DATA_TYPE = [
self::TYPE_COUPON_SEND => '优惠券发放明细',
self::TYPE_COUPON_USE => '优惠券使用明细',
];
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class Member extends Model
{
use SoftDeletes;
protected $connection = 'brand';
protected $table = 'member';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
public function pointLog()
{
return $this->hasMany(PointUserLog::class,'user_id');
}
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class MemberVipCard extends Model
{
use SoftDeletes;
protected $connection = 'brand';
protected $table = 'member_vip_card';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class MemberVipCardPeriod extends Model
{
use SoftDeletes;
protected $connection = 'brand';
protected $table = 'member_vip_card_period';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
}
<?php
declare ( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class OrderSet extends Model
{
protected $connection = 'brand';
protected $table = 'order_set';
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use App\Model\Brand\Brand;
class PointSet extends Model
{
protected $connection = 'brand';
protected $table = 'point_set';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
// 时间戳
protected $dateFormat = 'U';
/**
* 品牌商
*/
public function brand()
{
return $this->hasOne( Brand::class, 'brand_no', 'brand_id' );
}
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use App\Model\Brand\Brand;
class PointUserLog extends Model
{
protected $connection = 'brand';
protected $table = 'point_user_log';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
// 时间戳
protected $dateFormat = 'U';
protected $fillable = [
'brand_id',
'user_id',
'type',
'action',
'point',
'remark',
'unique_id',
];
}
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class Product extends Model
{
use SoftDeletes;
protected $connection = 'r_brand';
protected $table = 'product';
protected $hidden = [ 'password' ];
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
}
<?php
declare ( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class SmsGroupSendDetail extends Model
{
protected $connection = 'brand';
protected $table = 'sms_group_send_detail';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
public function history()
{
return $this->belongsTo(SmsGroupSendHistory::class,'log_id');
}
}
\ No newline at end of file
<?php
declare ( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class SmsGroupSendHistory extends Model
{
protected $connection = 'brand';
protected $table = 'sms_group_send_history';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
}
\ No newline at end of file
<?php
declare ( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class SmsSendHistory extends Model
{
protected $connection = 'brand';
protected $table = 'sms_send_history';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
}
\ No newline at end of file
<?php
declare ( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class SmsStatistics extends Model
{
protected $connection = 'brand';
protected $table = 'sms_statistics';
public $timestamps = false;
}
\ No newline at end of file
<?php
declare ( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class SmsSystemTemplate extends Model
{
use SoftDeletes;
protected $connection = 'brand';
protected $table = 'sms_system_template';
protected $dateFormat = 'U';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
}
<?php
declare ( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class SmsTemplate extends Model
{
use SoftDeletes;
protected $connection = 'brand';
protected $table = 'sms_template';
protected $dateFormat = 'U';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class Store extends Model
{
use SoftDeletes;
protected $connection = 'brand';
protected $table = 'store';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class StoreLevel extends Model
{
protected $connection = 'brand';
protected $table = 'store_level';
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class StoreLevelDemoteConfig extends Model
{
protected $connection = 'brand';
protected $table = 'store_level_demote_config';
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace App\Model\Brand;
use App\Model\Model;
class StoreRebateLog extends Model
{
protected $connection = 'brand';
protected $table = 'store_rebate_log';
public $timestamps = false;
protected $guarded = [];
}
\ No newline at end of file
<?php
declare(strict_types=1);
namespace App\Model\Cloud;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class TreasureActivity extends Model
{
use SoftDeletes;
protected $connection = 'cloud';
protected $table = 'treasure_activity';
protected $guarded = [];
/** @var int 参与范围 全部 */
const WITH_STORE_TYPE_ALL_VALUE = 1;
/** @var int 参与范围 指定 */
const WITH_STORE_TYPE_APPOINT_VALUE = 2;
/** @var int 参与范围 排除 */
const WITH_STORE_TYPE_EXCLUDE_VALUE = 3;
const ACT_TABLE_NAME = 'treasure_activity';
const ACT_STATUS_NO = 0;
const ACT_STATUS_YES = 1;
}
<?php
declare( strict_types=1 );
namespace App\Model\Code;
use App\Model\Model;
use Hyperf\DbConnection\Db;
use App\Model\Code\CodeOrderModel;
class BranchCodeModel extends Model
{
protected $connection = 'code';
protected $table = 'code_';
protected $brand_id = '';
protected $guarded = [];
public function __construct( array $attributes = [], $brand_id = '' )
{
parent::__construct( $attributes );
// 设置分表
$this->table = 'code_' . $brand_id;
$this->brand_id = $brand_id;
return $this;
}
public function syncCodes( $filePath )
{
// 格式化连接
if ( PHP_OS == 'WINNT' ) {
$filePath = str_replace( "\\","\\\\", $filePath );
$filePath = str_replace( '/',"\\\\", $filePath );
}
$prefix = $this->getConnection()->getConfig('prefix');
$table = $prefix.$this->getTable();
$rn=PHP_EOL;
$sql = <<<EOF
LOAD DATA LOCAL INFILE '{$filePath}' INTO TABLE {$table}
FIELDS TERMINATED BY ','
ENCLOSED BY ''
LINES TERMINATED BY '{$rn}'
IGNORE 1 LINES
(batch_sn,big_code,small_code,security_code,created_at);
EOF;
return Db::connection('code')->statement( $sql );
}
}
<?php
declare( strict_types=1 );
namespace App\Model\Code;
use App\Model\Model;
use Hyperf\DbConnection\Db;
use App\Constants\ErrorCode;
use Hyperf\Logger\LoggerFactory;
use App\Model\Code\CodeOrderModel;
use App\Exception\BusinessException;
use Hyperf\Database\Model\SoftDeletes;
/**
* 泊然恩码表中间表:贝因美数据写入此表,中源程序同步此表数据
*
*/
class CodeBreModel extends Model
{
protected $connection = 'code';
protected $table = 'code_bre_';
protected $brand_id = '';
protected $guarded = [];
public $timestamps = false;
public function __construct( array $attributes = [], $brand_id = '' )
{
parent::__construct( $attributes );
// 设置分表
$this->table = 'code_bre_' . $brand_id;
$this->brand_id = $brand_id;
return $this;
}
}
<?php
declare( strict_types=1 );
namespace App\Model\Ecpass;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class Order extends Model
{
use SoftDeletes;
protected $connection = 'ecpass';
protected $table = 'order';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
}
<?php
declare(strict_types=1);
namespace App\Model\Ecpass;
use App\Model\Model;
class OrderStatistics extends Model
{
protected $connection = 'ecpass';
protected $table = 'order_statistics';
const CREATED_AT = null;
const UPDATED_AT = null;
}
<?php
declare(strict_types=1);
namespace App\Model\Marketing;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
/**
* @property-read $plan
* @property-read \App\Model\Marketing\Template $template
*/
class Activity extends Model
{
use SoftDeletes;
protected $connection = 'brand';
/**
* 时间维护 创建 更新 删除
*/
const CREATED_AT = 'created_time';
const UPDATED_AT = 'last_change_time';
const DELETED_AT = 'deleted_time';
const IS_OPEN_ENABLE = 1;
const IS_OPEN_DISABLE = 0;
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'fw_activitys';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'brand_id', 'activity_name', 'activity_type', 'sort_level', 'status', 'start_time', 'end_time', 'template_uuid', 'award_type', 'remarks', 'is_rule', 'rule_title', 'rule_content',
'is_open_collect_data', 'open_collect_data', 'is_stint_first', 'is_stint_join', 'stint_join_data', 'is_stint_user', 'stint_user_data', 'is_stint_area', 'stint_area_data', 'is_stint_flee_goods', 'is_many_awards', 'many_awards_data', 'is_ploy', 'ploy_remark',
'state', 'created_time', 'created_by_id', 'last_change_time', 'change_by_id', 'deleted_time', 'deleted_by_id', 'activity_photo_id'
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'start_time' => 'datetime:Y-m-d H:i:s',
'end_time' => 'datetime:Y-m-d H:i:s',
'created_time' => 'datetime:Y-m-d H:i:s',
'open_collect_data' => 'json',
'stint_join_data' => 'json',
'stint_user_data' => 'json',
'stint_area_data' => 'json',
'many_awards_data' => 'json',
];
/**
* 活动ID
*
* @return void
*/
public function getActivityIdAttribute()
{
return $this->id;
}
/**
* 活动状态的标识 status_title
*/
public function getStatusTitleAttribute()
{
if ($this->is_open == self::IS_OPEN_DISABLE) {
return '已禁用';
}
$arr = [
'1' => '未开始',
'2' => '进行中',
'3' => '已结束',
'4' => '已禁用',
];
return $arr[$this->status] ?? '未开始';
}
/**
* 活动模板关联
*/
public function template()
{
return $this->hasOne(Template::class, 'template_uuid', 'template_uuid');
}
/**
* 获取活动范围 range
* @return array
*/
public function range()
{
return $this->hasMany(CodeLog::class, 'activity_id', 'id');
}
/**
* 获取活动进度 plan
* @return int
*/
public function getPlanAttribute()
{
$now_time = time();
$end_time = strtotime($this->end_time->format('Y-m-d H:i:s'));
$start_time = strtotime($this->start_time->format('Y-m-d H:i:s'));
if ($now_time < $start_time) {
return 0;
}
if ($now_time > $end_time) {
return 100;
}
return intval(($now_time - $start_time) / ($end_time - $start_time) * 100);
}
}
<?php
declare (strict_types=1);
namespace App\Model\Marketing;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
/**
* 黑名单
*/
class Blacklist extends Model
{
use SoftDeletes;
/**
* 时间维护 创建 更新 删除
*/
const CREATED_AT = 'created_time';
const UPDATED_AT = 'last_change_time';
const DELETED_AT = 'deleted_time';
protected $connection = 'brand';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'fw_blacklists';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'blacklist_limit_start' => 'datetime:Y-m-d H:i:s',
'blacklist_limit_end' => 'datetime:Y-m-d H:i:s',
'releasing_time' => 'datetime:Y-m-d H:i:s',
];
}
<?php
declare(strict_types=1);
namespace App\Model\Marketing;
use App\Model\Model;
use App\Model\Brand\Member;
use App\Model\Brand\Product;
use App\Model\Marketing\Activity;
use Hyperf\Database\Model\SoftDeletes;
/**
* 扫码明细
*/
class Scan extends Model
{
// use SoftDeletes;
/**
* 时间维护 创建 更新 删除
*/
const CREATED_AT = 'created_time';
const UPDATED_AT = 'last_change_time';
// const DELETED_AT = 'deleted_time';
protected $connection = 'brand';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'fw_scans';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'fw_first_time' => 'datetime:Y-m-d H:i:s',
'first_time' => 'datetime:Y-m-d H:i:s',
'created_time' => 'datetime:Y-m-d H:i:s',
];
/**
* 活动关联 activity
*/
public function activity()
{
return $this->hasOne(Activity::class, 'id', 'activity_id');
}
/**
* 关联 member
*/
public function member()
{
return $this->hasOne(Member::class, 'id', 'member_id');
}
/**
* 关联产品
*/
public function product()
{
return $this->hasOne(Product::class, 'id', 'product_id');
}
}
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论