diff --git a/app/data/controller/UserLevel.php b/app/data/controller/UserLevel.php index 5af467c30..717a317ae 100644 --- a/app/data/controller/UserLevel.php +++ b/app/data/controller/UserLevel.php @@ -2,7 +2,7 @@ namespace app\data\controller; -use app\data\service\PrizeService; +use app\data\service\RebateCurrentService; use think\admin\Controller; /** @@ -41,7 +41,7 @@ class UserLevel extends Controller foreach ($data as &$vo) { $vo['rebate_rule'] = str2arr($vo['rebate_rule']); foreach ($vo['rebate_rule'] as &$v) { - $v = PrizeService::instance()->name($v); + $v = RebateCurrentService::instance()->name($v); } } } @@ -77,7 +77,7 @@ class UserLevel extends Controller protected function _form_filter(array &$vo) { if ($this->request->isGet()) { - $this->prizes = PrizeService::PRIZES; + $this->prizes = RebateCurrentService::PRIZES; $vo['rebate_rule'] = str2arr($vo['rebate_rule'] ?? ''); } else { $vo['utime'] = time(); diff --git a/app/data/service/PrizeService.php b/app/data/service/RebateCurrentService.php similarity index 98% rename from app/data/service/PrizeService.php rename to app/data/service/RebateCurrentService.php index a3c3fda8f..571d84d88 100644 --- a/app/data/service/PrizeService.php +++ b/app/data/service/RebateCurrentService.php @@ -6,11 +6,11 @@ use think\admin\Service; use think\admin\Exception; /** - * 用户奖励配置 - * Class PrizeService + * 实时返利服务 + * Class RebateCurrentService * @package app\data\service */ -class PrizeService extends Service +class RebateCurrentService extends Service { const PRIZE_01 = 'prize_01'; const PRIZE_02 = 'prize_02'; @@ -75,7 +75,7 @@ class PrizeService extends Service $this->order = $this->app->db->name('ShopOrder')->where($map)->find(); if (empty($this->order)) throw new Exception('订单不存在'); // 获取用户数据 - $map = ['id' => $this->order['uid']]; + $map = ['id' => $this->order['uid'], 'deleted' => 0]; $this->user = $this->app->db->name('DataUser')->where($map)->find(); if (empty($this->user)) throw new Exception('用户不存在'); // 获取推荐用户 diff --git a/app/data/service/RebateMonthService.php b/app/data/service/RebateMonthService.php new file mode 100644 index 000000000..6c5638920 --- /dev/null +++ b/app/data/service/RebateMonthService.php @@ -0,0 +1,45 @@ +app->db->name('DataUser')->where(['id' => $uid])->find(); + if (empty($user)) throw new Exception("指定用户[{$uid}]不存在"); + $this->app->log->notice("开始处理用户[{$user['id']}]月度[{$this->date}]返利"); + $this->user = $user; + // $this->_prize_02(); + } + +} \ No newline at end of file diff --git a/app/data/service/RebateQuarterService.php b/app/data/service/RebateQuarterService.php new file mode 100644 index 000000000..d19193ac3 --- /dev/null +++ b/app/data/service/RebateQuarterService.php @@ -0,0 +1,56 @@ +quarter = ceil(date('n', mktime(0, 0, 0, $month, 1, $year)) / 3); + $this->dateAfter = date('Y-m-t 23:59:59', mktime(0, 0, 0, ($this->quarter - 1) * 3 + 0, 1, date('Y'))); + $this->dateStart = date('Y-m-01 00:00:00', mktime(0, 0, 0, ($this->quarter - 2) * 3 + 1, 1, date('Y'))); + return $this; + } + + /** + * 指定用户发放奖励 + * @param mixed $uid + * @param array $user + * @throws Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function execute($uid, $user = []) + { + if (empty($user)) $user = $this->app->db->name('DataUser')->where(['id' => $uid])->find(); + if (empty($user)) throw new Exception("指定用户[{$uid}]不存在"); + $this->app->log->notice("开始处理用户[{$user['id']}]季度[{$this->dateStart} - {$this->dateAfter}]返利"); + // $this->_prize_05($user); + } +} \ No newline at end of file diff --git a/app/data/service/RebateYearService.php b/app/data/service/RebateYearService.php new file mode 100644 index 000000000..c47c31cd8 --- /dev/null +++ b/app/data/service/RebateYearService.php @@ -0,0 +1,50 @@ +year = $year ?: date('Y', strtotime('-1 year')); + return $this; + } + + /** + * 指定用户发放奖励 + * @param mixed $uid + * @param array $user + * @throws Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function execute($uid, $user = []) + { + if (empty($user)) $user = $this->app->db->name('DataUser')->where(['id' => $uid])->find(); + if (empty($user)) throw new Exception("指定用户[{$uid}]不存在"); + $this->app->log->notice("开始处理用户[{$user['id']}]年度[{$this->year}]返利"); + $this->user = $user; + // $this->_prize_06(); + } + +} \ No newline at end of file diff --git a/app/data/sys.php b/app/data/sys.php index dd0220bc8..d1fd22ed9 100644 --- a/app/data/sys.php +++ b/app/data/sys.php @@ -8,11 +8,17 @@ use think\Console; if (app()->request->isCli()) { Console::starting(function (Console $console) { + $console->addCommand(UserLevel::class); $console->addCommand(OrderClear::class); $console->addCommand(UserBalance::class); - $console->addCommand(UserLevel::class); $console->addCommand(UserTransfer::class); }); +} else { + // 注册订单支付处理事件 + app()->event->listen('ShopOrderPayment', function ($orderNo) { + app()->log->notice("订单支付事件,订单号:{$orderNo}"); + \app\data\service\RebateCurrentService::instance()->execute($orderNo); + }); } if (!function_exists('show_goods_spec')) { diff --git a/vendor/services.php b/vendor/services.php index 73a7da04b..56250ed8a 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\admin\\Library',