GlobalController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace console\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\stat\classes\StatItemClass;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizGhs\order\classes\OrderItemClass;
  7. use bizGhs\product\classes\ProductClass;
  8. //use bizHd\stat\classes\StatVisitClass;
  9. use bizGhs\stat\classes\StatVisitClass;
  10. use common\components\dict;
  11. use Yii;
  12. use yii\console\Controller;
  13. /**
  14. * 全局脚本
  15. */
  16. class GlobalController extends Controller
  17. {
  18. // ./yii global/run
  19. public function actionRun()
  20. {
  21. ini_set('memory_limit', '2045M');
  22. set_time_limit(0);
  23. //库存预警每天下午3点通知一次
  24. $hour = date("Hi");
  25. if ($hour == '1500') {
  26. ProductClass::allShopStockWarningFromQueue();
  27. }
  28. //花材单独统计
  29. OrderItemClass::refreshBelongCost();
  30. if ((int)date('i') % 20 == 0) {
  31. //不知道为什么线上付的结账单,老是会被取消,要恢复回来!!!!!!!!!!!!!!!!!!!!
  32. $sql = "update xhClear set status=2 where status=3 and thirdNo!=''";
  33. Yii::$app->db->createCommand($sql)->execute();
  34. }
  35. //每3分钟进行已完成支付订单处理:花材销量统计
  36. if ((int)date('i') % 3 == 0) {
  37. $ghs = dict::getDict('ptStyle', 'ghs');
  38. $shopList = ShopClass::getAllByCondition(['ptStyle' => $ghs], null, '*', null, true);
  39. if (!empty($shopList)) {
  40. foreach ($shopList as $key => $shop) {
  41. $ids = [];
  42. $shopId = $shop->id ?? 0;
  43. $newOrderKey = 'ghsNewOrder_' . $shopId;
  44. while ($count = Yii::$app->redis->executeCommand('LLEN', [$newOrderKey])) {
  45. $id = Yii::$app->redis->executeCommand('RPOP', [$newOrderKey]);
  46. if (is_numeric($id)) {
  47. $ids[] = $id;
  48. }
  49. }
  50. if (empty($ids)) {
  51. continue;
  52. }
  53. $list = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  54. if (empty($list)) {
  55. continue;
  56. }
  57. foreach ($list as $key => $order) {
  58. $orderSn = $order->orderSn ?? '';
  59. if (empty($orderSn)) {
  60. continue;
  61. }
  62. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  63. if (empty($itemList)) {
  64. continue;
  65. }
  66. //花材销量统计
  67. foreach ($itemList as $itemKey => $itemVal) {
  68. $mainId = $itemVal->mainId ?? 0;
  69. $itemId = $itemVal->productId ?? 0;
  70. $num = $itemVal->num ?? 0;
  71. $price = $itemVal->price ?? 0;
  72. $params = [
  73. 'mainId' => $mainId,
  74. 'itemId' => $itemId,
  75. 'price' => $price,
  76. 'num' => $num,
  77. ];
  78. StatItemClass::replace($params);
  79. }
  80. }
  81. }
  82. }
  83. }
  84. //每天凌晨00:10保存昨天访客数
  85. if ($hour == '0010') {
  86. $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
  87. if (!empty($shopList)) {
  88. foreach ($shopList as $shop) {
  89. //昨天
  90. $date = date("Ymd", strtotime("-1 day"));
  91. //今天
  92. //$date = date("Ymd");
  93. $visitNum = StatVisitClass::getVisitNum($shop, $date);
  94. $currentNum = bcadd($shop->totalVisit, $visitNum, 2);
  95. $shop->totalVisit = $currentNum;
  96. $shop->save();
  97. StatVisitClass::saveVisit($shop, $visitNum, $date);
  98. }
  99. }
  100. }
  101. }
  102. }