GlobalController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace console\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\market\classes\TjFlClass;
  5. use biz\shop\classes\ShopClass;
  6. use biz\sj\classes\SjClass;
  7. use biz\stat\classes\StatItemClass;
  8. use bizGhs\custom\classes\CustomClass;
  9. use bizGhs\custom\services\CustomService;
  10. use bizGhs\order\classes\OrderClass;
  11. use bizGhs\order\classes\OrderItemClass;
  12. use bizGhs\product\classes\ProductClass;
  13. use bizHd\stat\classes\StatVisitClass;
  14. use common\components\dict;
  15. use Yii;
  16. use yii\console\Controller;
  17. /**
  18. * 全局脚本
  19. */
  20. class GlobalController extends Controller
  21. {
  22. // ./yii global/run
  23. public function actionRun()
  24. {
  25. //库存预警每天下午3点通知一次
  26. $hour = date("Hi");
  27. if ($hour == '1500') {
  28. ProductClass::allShopStockWarningFromQueue();
  29. }
  30. //每2分钟进行已完成支付订单处理,花材销量统计、推荐新客发红包
  31. if ((int)date('i') % 2 == 0) {
  32. $ghs = dict::getDict('ptStyle', 'ghs');
  33. $shopList = ShopClass::getAllByCondition(['ptStyle' => $ghs], null, '*', null, true);
  34. if (!empty($shopList)) {
  35. foreach ($shopList as $key => $shop) {
  36. $ids = [];
  37. $shopId = $shop->id ?? 0;
  38. $newOrderKey = 'ghsNewOrder_' . $shopId;
  39. while ($count = Yii::$app->redis->executeCommand('LLEN', [$newOrderKey])) {
  40. $id = Yii::$app->redis->executeCommand('RPOP', [$newOrderKey]);
  41. if (is_numeric($id)) {
  42. $ids[] = $id;
  43. }
  44. }
  45. if (empty($ids)) {
  46. continue;
  47. }
  48. $list = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  49. if (empty($list)) {
  50. continue;
  51. }
  52. foreach ($list as $key => $order) {
  53. $orderSn = $order->orderSn ?? '';
  54. if (empty($orderSn)) {
  55. continue;
  56. }
  57. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  58. if (empty($itemList)) {
  59. continue;
  60. }
  61. //花材销量统计
  62. foreach ($itemList as $itemKey => $itemVal) {
  63. StatItemClass::replace($itemVal);
  64. }
  65. //推荐新客下单,发推荐新客奖励
  66. $tjFl = $shop->tjFl ?? 0;
  67. if ($tjFl == 1) {
  68. $customId = $order->customId ?? 0;
  69. $hostShopId = $order->shopId ?? 0;
  70. $custom = CustomClass::getById($customId, true);
  71. if (!empty($custom)) {
  72. $ghsId = $custom->ghsId ?? 0;
  73. $ghs = GhsClass::getById($ghsId, true);
  74. $hasOrder = $custom->hasOrder ?? 0;
  75. $hasCg = $ghs->hasCg ?? 0;
  76. if ($hasOrder == 0 && $hasCg == 0) {
  77. $custom->hasOrder = 1;
  78. $custom->save();
  79. $ghs->hasCg = 1;
  80. $ghs->save();
  81. $customSjId = $custom->sjId ?? 0;
  82. $sj = SjClass::getById($customSjId, true);
  83. //下单客户的介绍人如果是自己客户则发福利
  84. $parentShopId = $sj->parentShopId ?? 0;
  85. $tjCustom = CustomClass::getByCondition(['shopId' => $parentShopId, 'ownShopId' => $hostShopId], true);
  86. $tjGhsId = $tjCustom->ghsId ?? 0;
  87. $tjGhs = GhsClass::getById($tjGhsId, true);
  88. TjFlClass::giveGift($tjGhs, $tjCustom, $custom);
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. //每天凌晨00:10保存昨天访客数
  97. if ($hour == '0010') {
  98. $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
  99. if (!empty($shopList)) {
  100. foreach ($shopList as $shop) {
  101. //昨天
  102. $date = date("Ymd", strtotime("-1 day"));
  103. //今天
  104. //$date = date("Ymd");
  105. $visitNum = StatVisitClass::getVisitNum($shop, $date);
  106. $currentNum = bcadd($shop->totalVisit, $visitNum, 2);
  107. $shop->totalVisit = $currentNum;
  108. $shop->save();
  109. StatVisitClass::saveVisit($shop, $visitNum, $date);
  110. }
  111. }
  112. }
  113. }
  114. }