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]; } }