sjId; $shopId = $shop->id; $time = date('Ymd'); $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time], true); if (empty($stat)) { $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'time' => $time, 'num' => 0], true); } $id = $stat->id; $unique = self::getLockById($id); if (empty($unique)) { util::fail('没有记录'); } $currentAmount = bcadd($unique->amount, $amount, 2); $unique->amount = $currentAmount; $unique->totalAmount = $shop->totalPurchase; $unique->num += 1; $unique->save(); //当月 StatCgMonthClass::replace($shop, $amount); } //今日采购 public static function getTodayCg($shop) { $start = date('Ymd'); $end = date("Ymd"); $shopId = $shop->id; $sjId = $shop->sjId; return self::getByTime($sjId, $shopId, $start, $end); } //昨日采购 public static function getYesterdayCg($shop) { $start = date('Ymd', strtotime("-1 days")); $end = date('Ymd', strtotime("-1 days")); $shopId = $shop->id; $sjId = $shop->sjId; return self::getByTime($sjId, $shopId, $start, $end); } //7日采购 public static function getSevenCg($shop) { $end = date('Ymd'); $start = date('Ymd', strtotime("-6 days")); $shopId = $shop->id; $sjId = $shop->sjId; return self::getByTime($sjId, $shopId, $start, $end); } //30日采购 public static function getThirtyCg($shop) { $end = date('Ymd'); $start = date('Ymd', strtotime("-29 days")); $shopId = $shop->id; $sjId = $shop->sjId; return self::getByTime($sjId, $shopId, $start, $end); } public static function getByTime($sjId, $shopId, $start, $end) { $where = []; $where['sjId'] = $sjId; $where['shopId'] = $shopId; $where['time'] = ['between', [$start, $end]]; $res = self::getAllByCondition($where, null, "num,amount"); $num = 0; $amount = 0; if ($res) { foreach ($res as $v) { $num += $v['num']; $amount = bcadd($v['amount'], $amount, 2); } } return ['num' => $num, 'amount' => $amount]; } }