mainId ?? 0; $where = ['mainId' => $mainId, 'time' => $time]; $model = self::getByCondition($where, true); if (empty($model)) { $data = ['mainId' => $mainId, 'time' => $time, 'amount' => 0, 'totalAmount' => $main->totalIncome, 'createTime' => date('Y-m-d H:i:s')]; $model = self::add($data, true); } $id = $model->id; //查id行级锁 $stat = StatIncomeClass::getLockById($id); $stat->amount = bcadd($amount, $stat->amount, 2); $stat->totalAmount = $main->totalIncome; $stat->save(); //每月 StatIncomeMonthClass::updateOrInsert($main, $shop, $amount); } //查询当天收入金额 public static function getAmountToday($shopId) { $time = date('Ymd'); $res = self::getDetail($shopId, $time); return $res['amount'] ?? 0; } //yesterday public static function getAmountYesterday($shopId) { $time = date('Ymd', strtotime("-1 days")); $res = self::getDetail($shopId, $time); return $res['amount'] ?? 0; } //近七天收入金额 public static function getAmountWeek($shopId) { $end = date('Ymd'); $start = date('Ymd', strtotime("-7 days")); return self::getAmountByTime($shopId, $start, $end); } //30天输入金额 public static function getAmountThirty($shopId) { $end = date('Ymd'); $start = date('Ymd', strtotime("-30 days")); return self::getAmountByTime($shopId, $start, $end); } //查询某一天的信息 public static function getDetail($shopId, $time) { $where = [ 'shopId' => $shopId, 'time' => $time, ]; $model = self::getByCondition($where); return $model; } public static function getAmountByTime($shopId, $start, $end) { $where = []; $where['shopId'] = $shopId; $where['time'] = ['between', [$start, $end]]; $res = self::getAllByCondition($where, null, "amount"); $amount = 0; if ($res) { foreach ($res as $v) { $amount = bcadd($amount, $v['amount'], 2); } } return $amount; } }