$time, 'amount' => $totalFee, 'sjId' => $sjId, 'addTime' => $addTime, 'weixin' => $weixin, 'alipay' => $alipay, 'balancePay' => $balancePay, 'cash' => $cash, ]; self::add($data); } else { $amount = stringUtil::calcAdd($income['amount'], $totalFee); $weixin = stringUtil::calcAdd($income['weixin'], $weixin); $cash = stringUtil::calcAdd($income['cash'], $cash); $balancePay = stringUtil::calcAdd($income['balancePay'], $balancePay); $alipay = stringUtil::calcAdd($income['alipay'], $alipay); $data = [ 'amount' => $amount, 'weixin' => $weixin, 'alipay' => $alipay, 'balancePay' => $balancePay, 'cash' => $cash, ]; self::updateByIds($sjId, $time, $data); } } public static function updateByIds($sjId, $time, $data) { xhStatIncome::updateByCondition(['time' => $time, 'sjId' => $sjId], $data); self::getByIds($sjId, $time); $cacheKey = dict::getCacheKey('xhStatIncome') . '_' . $sjId . '_' . $time; $params = [$cacheKey]; if (!empty($data)) { foreach ($data as $key => $val) { $params[] = $key; $params[] = $val; } } Yii::$app->redis->executeCommand('HMSET', $params); return self::getByIds($sjId, $time); } public static function add($data) { $return = xhStatIncome::add($data); return $return; } public static function getByIds($sjId, $time) { $income = xhStatIncome::find()->where(['sjId' => $sjId, 'time' => $time])->asArray()->one(); return $income; } public static function getTodayIncome($sjId, $time) { $income = self::getByIds($sjId, $time); $amount = 0; if (!empty($income)) { $amount = $income['amount']; } return $amount; } public static function getLatestIncome($sjId) { $num = 14;//取最近15天 $arr = []; $dateList = []; $amountList = []; for ($i = $num; $i >= 0; $i--) { $time = strtotime(date("Y-m-d")) - $i * 86400; $date = date("n/j", $time); $income = self::getByIds($sjId, $time); $amount = 0; if (!empty($income)) { $amount = $income['amount']; } $arr[$date] = $amount; $dateList[] = $date; $amountList[] = $amount; } return ['list' => $arr, 'date' => $dateList, 'amount' => $amountList]; } }