| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace bizHd\stat\classes;
- use bizHd\order\classes\OrderClass;
- use bizHd\order\classes\OrderGoodsClass;
- use bizHd\stat\models\StatOrder;
- use bizHd\base\classes\BaseClass;
- class StatOrderClass extends BaseClass
- {
- public static $baseFile = '\bizHd\stat\models\StatOrder';
- //今日订单+1
- public static function updateOrInsert($main, $shop)
- {
- $time = date('Ymd');
- $mainId = $shop->mainId ?? 0;
- $where = ['mainId' => $mainId, 'time' => $time];
- $model = self::getByCondition($where, true);
- if (empty($model)) {
- $model = self::add(['mainId' => $mainId, 'time' => $time, 'riseNum' => 0, 'totalNum' => $main->totalOrderNum], true);
- }
- $id = $model->id;
- //查id行级锁
- $stat = StatOrderClass::getLockById($id);
- $stat->riseNum += 1;
- $stat->totalNum += 1;
- $stat->save();
- //本月订单+1
- StatOrderMonthClass::updateOrInsert($main, $shop);
- }
- public static function getRiseNumToday($shopId)
- {
- $time = date('Ymd');
- $res = self::getDetail($shopId, $time);
- return $res['riseNum'] ?? 0;
- }
- //yesterday
- public static function getRiseNumYesterday($shopId)
- {
- $time = date('Ymd', strtotime("-1 days"));
- $res = self::getDetail($shopId, $time);
- return $res['riseNum'] ?? 0;
- }
- public static function getDetail($shopId, $time)
- {
- $where = [
- 'shopId' => $shopId,
- 'time' => $time,
- ];
- $model = self::getByCondition($where);
- return $model;
- }
- //近7天
- public static function getRiseNumWeek($shopId)
- {
- $end = date('Ymd');
- $start = date('Ymd', strtotime("-6 days"));
- return self::getRiseNumByTime($shopId, $start, $end);
- }
- //近30天
- public static function getRiseNumThirty($shopId)
- {
- $end = date('Ymd');
- $start = date('Ymd', strtotime("-29 days"));
- return self::getRiseNumByTime($shopId, $start, $end);
- }
- public static function getRiseNumByTime($shopId, $start, $end)
- {
- $where = [];
- $where['shopId'] = $shopId;
- $where['time'] = ['between', [$start, $end]];
- $res = self::getAllByCondition($where, null, "riseNum");
- $riseNum = 0;
- if ($res) {
- foreach ($res as $v) {
- $riseNum = bcadd($riseNum, $v['riseNum'], 0);
- }
- }
- return $riseNum;
- }
- //获取花束数量 ssh 202320
- public static function statHsNum($mainId)
- {
- $todayDate = date('Y-m-d');
- $todayStartTime = $todayDate . ' 00:00:00';
- $todayEndTime = $todayDate . ' 23:59:59';
- $where = ['mainId' => $mainId, 'payStatus' => 1];
- $where['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
- $totalNum = 0;
- $orderList = OrderClass::getAllByCondition($where, null, '*', null, true);
- if (!empty($orderList)) {
- foreach ($orderList as $order) {
- $orderSn = $order->orderSn ?? '';
- $sonList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($sonList)) {
- foreach ($sonList as $son) {
- $flower = $son->flower ?? 0;
- if ($flower == 0) {
- continue;
- }
- $kindId = $son->kindId ?? 0;
- if (empty($kindId)) {
- continue;
- }
- $num = $son->num ?? 0;
- $totalNum = bcadd($totalNum, $num);
- }
- }
- }
- }
- return ['num' => $totalNum];
- }
- }
|