| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- namespace console\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\market\classes\TjFlClass;
- use biz\shop\classes\ShopClass;
- use biz\sj\classes\SjClass;
- use biz\stat\classes\StatItemClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\classes\OrderItemClass;
- use bizGhs\product\classes\ProductClass;
- use bizHd\stat\classes\StatVisitClass;
- use common\components\dict;
- use Yii;
- use yii\console\Controller;
- /**
- * 全局脚本
- */
- class GlobalController extends Controller
- {
- // ./yii global/run
- public function actionRun()
- {
- //库存预警每天下午3点通知一次
- $hour = date("Hi");
- if ($hour == '1500') {
- ProductClass::allShopStockWarningFromQueue();
- }
- //每2分钟进行已完成支付订单处理,花材销量统计、推荐新客发红包
- if ((int)date('i') % 2 == 0) {
- $ghs = dict::getDict('ptStyle', 'ghs');
- $shopList = ShopClass::getAllByCondition(['ptStyle' => $ghs], null, '*', null, true);
- if (!empty($shopList)) {
- foreach ($shopList as $key => $shop) {
- $ids = [];
- $shopId = $shop->id ?? 0;
- $newOrderKey = 'ghsNewOrder_' . $shopId;
- while ($count = Yii::$app->redis->executeCommand('LLEN', [$newOrderKey])) {
- $id = Yii::$app->redis->executeCommand('RPOP', [$newOrderKey]);
- if (is_numeric($id)) {
- $ids[] = $id;
- }
- }
- if (empty($ids)) {
- continue;
- }
- $list = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
- if (empty($list)) {
- continue;
- }
- foreach ($list as $key => $order) {
- $orderSn = $order->orderSn ?? '';
- if (empty($orderSn)) {
- continue;
- }
- $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (empty($itemList)) {
- continue;
- }
- //花材销量统计
- foreach ($itemList as $itemKey => $itemVal) {
- StatItemClass::replace($itemVal);
- }
- //推荐新客发红包
- $tjFl = $shop->tjFl ?? 0;
- if ($tjFl == 1) {
- $customId = $order->customId ?? 0;
- $hostShopId = $order->shopId ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (!empty($custom)) {
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- $hasOrder = $custom->hasOrder ?? 0;
- $hasCg = $ghs->hasCg ?? 0;
- if ($hasOrder == 0 && $hasCg == 0) {
- $custom->hasOrder = 1;
- $custom->save();
- $ghs->hasCg = 1;
- $ghs->save();
- $customSjId = $custom->sjId ?? 0;
- $sj = SjClass::getById($customSjId, true);
- //下单客户的介绍人如果是自己客户则发福利
- $parentShopId = $sj->parentShopId ?? 0;
- $tjCustom = CustomClass::getByCondition(['shopId' => $parentShopId, 'ownShopId' => $hostShopId], true);
- $tjGhsId = $tjCustom->ghsId ?? 0;
- $tjGhs = GhsClass::getById($tjGhsId, true);
- TjFlClass::giveGift($tjGhs, $tjCustom, $custom);
- }
- }
- }
- }
- }
- }
- }
- //每天凌晨00:10保存昨天访客数
- if ($hour == '0010') {
- $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
- if (!empty($shopList)) {
- foreach ($shopList as $shop) {
- //昨天
- $date = date("Ymd", strtotime("-1 day"));
- //今天
- //$date = date("Ymd");
- $visitNum = StatVisitClass::getVisitNum($shop, $date);
- $currentNum = bcadd($shop->totalVisit, $visitNum, 2);
- $shop->totalVisit = $currentNum;
- $shop->save();
- StatVisitClass::saveVisit($shop, $visitNum, $date);
- }
- }
- }
- }
- }
|