StatOrderClass.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace bizHd\stat\classes;
  3. use bizHd\order\classes\OrderClass;
  4. use bizHd\order\classes\OrderGoodsClass;
  5. use bizHd\stat\models\StatOrder;
  6. use bizHd\base\classes\BaseClass;
  7. class StatOrderClass extends BaseClass
  8. {
  9. public static $baseFile = '\bizHd\stat\models\StatOrder';
  10. //今日订单+1
  11. public static function updateOrInsert($main, $shop)
  12. {
  13. $time = date('Ymd');
  14. $mainId = $shop->mainId ?? 0;
  15. $where = ['mainId' => $mainId, 'time' => $time];
  16. $model = self::getByCondition($where, true);
  17. if (empty($model)) {
  18. $model = self::add(['mainId' => $mainId, 'time' => $time, 'riseNum' => 0, 'totalNum' => $main->totalOrderNum], true);
  19. }
  20. $id = $model->id;
  21. //查id行级锁
  22. $stat = StatOrderClass::getLockById($id);
  23. $stat->riseNum += 1;
  24. $stat->totalNum += 1;
  25. $stat->save();
  26. //本月订单+1
  27. StatOrderMonthClass::updateOrInsert($main, $shop);
  28. }
  29. public static function getRiseNumToday($shopId)
  30. {
  31. $time = date('Ymd');
  32. $res = self::getDetail($shopId, $time);
  33. return $res['riseNum'] ?? 0;
  34. }
  35. //yesterday
  36. public static function getRiseNumYesterday($shopId)
  37. {
  38. $time = date('Ymd', strtotime("-1 days"));
  39. $res = self::getDetail($shopId, $time);
  40. return $res['riseNum'] ?? 0;
  41. }
  42. public static function getDetail($shopId, $time)
  43. {
  44. $where = [
  45. 'shopId' => $shopId,
  46. 'time' => $time,
  47. ];
  48. $model = self::getByCondition($where);
  49. return $model;
  50. }
  51. //近7天
  52. public static function getRiseNumWeek($shopId)
  53. {
  54. $end = date('Ymd');
  55. $start = date('Ymd', strtotime("-6 days"));
  56. return self::getRiseNumByTime($shopId, $start, $end);
  57. }
  58. //近30天
  59. public static function getRiseNumThirty($shopId)
  60. {
  61. $end = date('Ymd');
  62. $start = date('Ymd', strtotime("-29 days"));
  63. return self::getRiseNumByTime($shopId, $start, $end);
  64. }
  65. public static function getRiseNumByTime($shopId, $start, $end)
  66. {
  67. $where = [];
  68. $where['shopId'] = $shopId;
  69. $where['time'] = ['between', [$start, $end]];
  70. $res = self::getAllByCondition($where, null, "riseNum");
  71. $riseNum = 0;
  72. if ($res) {
  73. foreach ($res as $v) {
  74. $riseNum = bcadd($riseNum, $v['riseNum'], 0);
  75. }
  76. }
  77. return $riseNum;
  78. }
  79. //获取花束数量 ssh 202320
  80. public static function statHsNum($mainId)
  81. {
  82. $todayDate = date('Y-m-d');
  83. $todayStartTime = $todayDate . ' 00:00:00';
  84. $todayEndTime = $todayDate . ' 23:59:59';
  85. $where = ['mainId' => $mainId, 'payStatus' => 1];
  86. $where['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
  87. $totalNum = 0;
  88. $orderList = OrderClass::getAllByCondition($where, null, '*', null, true);
  89. if (!empty($orderList)) {
  90. foreach ($orderList as $order) {
  91. $orderSn = $order->orderSn ?? '';
  92. $sonList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  93. if (!empty($sonList)) {
  94. foreach ($sonList as $son) {
  95. $flower = $son->flower ?? 0;
  96. if ($flower == 0) {
  97. continue;
  98. }
  99. $kindId = $son->kindId ?? 0;
  100. if (empty($kindId)) {
  101. continue;
  102. }
  103. $num = $son->num ?? 0;
  104. $totalNum = bcadd($totalNum, $num);
  105. }
  106. }
  107. }
  108. }
  109. return ['num' => $totalNum];
  110. }
  111. }