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 = StatIncomeMonthClass::getLockById($id); $stat->amount = bcadd($amount, $stat->amount, 2); $stat->totalAmount = $main->totalIncome; $stat->save(); } //查询当天收入金额 public static function getAmountMonth($shopId) { $time = date('Ym'); $res = self::getDetail($shopId, $time); return $res['amount'] ?? 0; } //查询某一个月的信息 public static function getDetail($shopId, $time) { $where = [ 'shopId' => $shopId, 'time' => $time, ]; $model = self::getByCondition($where); return $model; } }