GlobalController.php 5.0 KB

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