|
|
@@ -9,121 +9,120 @@ use common\components\stringUtil;
|
|
|
|
|
|
class xhStatIncomeService
|
|
|
{
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加与更新
|
|
|
- */
|
|
|
- public static function replace($merchantId, $totalFee, $payWay)
|
|
|
- {
|
|
|
-
|
|
|
- if ($totalFee <= 0) {
|
|
|
- return ture;
|
|
|
- }
|
|
|
- $time = date("Ymd");
|
|
|
- $income = self::getByIds($merchantId, $time);
|
|
|
- $weixin = 0;
|
|
|
- $alipay = 0;
|
|
|
- $balancePay = 0;
|
|
|
- $cash = 0;
|
|
|
- $addTime = time();
|
|
|
- $payList = configDict::getConfig('payWay');
|
|
|
- if ($payList['weixinPay'] == $payWay) {
|
|
|
- $weixin = $totalFee;
|
|
|
- } elseif ($payWay == $payList['alipay']) {
|
|
|
- $alipay = $totalFee;
|
|
|
- } elseif ($payWay == $payList['balancePay']) {
|
|
|
- $balancePay = $totalFee;
|
|
|
- } elseif ($payWay == $payList['cashPay']) {
|
|
|
- $cash = $totalFee;
|
|
|
- } elseif ($payWay == $payList['mini']) {
|
|
|
- $weixin = $totalFee;
|
|
|
- }
|
|
|
- if (empty($income)) {
|
|
|
- $data = [
|
|
|
- 'time' => $time,
|
|
|
- 'amount' => $totalFee,
|
|
|
- 'merchantId' => $merchantId,
|
|
|
- '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($merchantId, $time, $data);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static function updateByIds($merchantId, $time, $data)
|
|
|
- {
|
|
|
- xhStatIncome::updateByCondition(['time' => $time, 'merchantId' => $merchantId], $data);
|
|
|
- self::getByIds($merchantId, $time);
|
|
|
- $cacheKey = configDict::getCacheKey('xhStatIncome') . '_' . $merchantId . '_' . $time;
|
|
|
- $params = [$cacheKey];
|
|
|
- if (!empty($data)) {
|
|
|
- foreach ($data as $key => $val) {
|
|
|
- $params[] = $key;
|
|
|
- $params[] = $val;
|
|
|
- }
|
|
|
- }
|
|
|
- Yii::$app->redis->executeCommand('HMSET', $params);
|
|
|
- return self::getByIds($merchantId, $time);
|
|
|
- }
|
|
|
-
|
|
|
- public static function add($data)
|
|
|
- {
|
|
|
- $return = xhStatIncome::add($data);
|
|
|
- return $return;
|
|
|
- }
|
|
|
-
|
|
|
- public static function getByIds($merchantId, $time)
|
|
|
- {
|
|
|
- $income = xhStatIncome::find()->where(['merchantId' => $merchantId, 'time' => $time])->asArray()->one();
|
|
|
- return $income;
|
|
|
- }
|
|
|
-
|
|
|
- public static function getTodayIncome($merchantId, $time)
|
|
|
- {
|
|
|
- $income = self::getByIds($merchantId, $time);
|
|
|
- $amount = 0;
|
|
|
- if (!empty($income)) {
|
|
|
- $amount = $income['amount'];
|
|
|
- }
|
|
|
- return $amount;
|
|
|
- }
|
|
|
-
|
|
|
- public static function getLatestIncome($merchantId)
|
|
|
- {
|
|
|
- $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($merchantId, $time);
|
|
|
- $amount = 0;
|
|
|
- if (!empty($income)) {
|
|
|
- $amount = $income['amount'];
|
|
|
- }
|
|
|
- $arr[$date] = $amount;
|
|
|
- $dateList[] = $date;
|
|
|
- $amountList[] = $amount;
|
|
|
- }
|
|
|
- return ['list' => $arr, 'date' => $dateList, 'amount' => $amountList];
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加与更新
|
|
|
+ */
|
|
|
+ public static function replace($merchantId, $totalFee, $payWay)
|
|
|
+ {
|
|
|
+ if ($totalFee <= 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ $time = date("Ymd");
|
|
|
+ $income = self::getByIds($merchantId, $time);
|
|
|
+ $weixin = 0;
|
|
|
+ $alipay = 0;
|
|
|
+ $balancePay = 0;
|
|
|
+ $cash = 0;
|
|
|
+ $addTime = time();
|
|
|
+ $payList = configDict::getConfig('payWay');
|
|
|
+ if ($payList['weixinPay'] == $payWay) {
|
|
|
+ $weixin = $totalFee;
|
|
|
+ } elseif ($payWay == $payList['alipay']) {
|
|
|
+ $alipay = $totalFee;
|
|
|
+ } elseif ($payWay == $payList['balancePay']) {
|
|
|
+ $balancePay = $totalFee;
|
|
|
+ } elseif ($payWay == $payList['cashPay']) {
|
|
|
+ $cash = $totalFee;
|
|
|
+ } elseif ($payWay == $payList['mini']) {
|
|
|
+ $weixin = $totalFee;
|
|
|
+ }
|
|
|
+ if (empty($income)) {
|
|
|
+ $data = [
|
|
|
+ 'time' => $time,
|
|
|
+ 'amount' => $totalFee,
|
|
|
+ 'merchantId' => $merchantId,
|
|
|
+ '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($merchantId, $time, $data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function updateByIds($merchantId, $time, $data)
|
|
|
+ {
|
|
|
+ xhStatIncome::updateByCondition(['time' => $time, 'merchantId' => $merchantId], $data);
|
|
|
+ self::getByIds($merchantId, $time);
|
|
|
+ $cacheKey = configDict::getCacheKey('xhStatIncome') . '_' . $merchantId . '_' . $time;
|
|
|
+ $params = [$cacheKey];
|
|
|
+ if (!empty($data)) {
|
|
|
+ foreach ($data as $key => $val) {
|
|
|
+ $params[] = $key;
|
|
|
+ $params[] = $val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Yii::$app->redis->executeCommand('HMSET', $params);
|
|
|
+ return self::getByIds($merchantId, $time);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function add($data)
|
|
|
+ {
|
|
|
+ $return = xhStatIncome::add($data);
|
|
|
+ return $return;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getByIds($merchantId, $time)
|
|
|
+ {
|
|
|
+ $income = xhStatIncome::find()->where(['merchantId' => $merchantId, 'time' => $time])->asArray()->one();
|
|
|
+ return $income;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getTodayIncome($merchantId, $time)
|
|
|
+ {
|
|
|
+ $income = self::getByIds($merchantId, $time);
|
|
|
+ $amount = 0;
|
|
|
+ if (!empty($income)) {
|
|
|
+ $amount = $income['amount'];
|
|
|
+ }
|
|
|
+ return $amount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getLatestIncome($merchantId)
|
|
|
+ {
|
|
|
+ $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($merchantId, $time);
|
|
|
+ $amount = 0;
|
|
|
+ if (!empty($income)) {
|
|
|
+ $amount = $income['amount'];
|
|
|
+ }
|
|
|
+ $arr[$date] = $amount;
|
|
|
+ $dateList[] = $date;
|
|
|
+ $amountList[] = $amount;
|
|
|
+ }
|
|
|
+ return ['list' => $arr, 'date' => $dateList, 'amount' => $amountList];
|
|
|
+ }
|
|
|
+
|
|
|
}
|