GlobalController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. $onlinePay = $order->onlinePay ?? 1;
  67. if ($tjFl == 1 && $onlinePay == 2) {
  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. }