Kaynağa Gözat

数据统计

shish 6 yıl önce
ebeveyn
işleme
00ec0921e0

+ 3 - 0
biz/stat/services/StatIncomeSourceService.php

@@ -26,6 +26,9 @@ class StatIncomeSourceService extends BaseService
         $merchantId = $data['merchantId'];
         $sourceType = $data['sourceType'];
         $amount = $data['amount'];
+        if ($amount <= 0) {
+            return true;
+        }
         $addTime = time();
         $income = self::getByCondition(['merchantId' => $merchantId, 'time' => $time, 'sourceType' => $sourceType], true);
         if (empty($income)) {

+ 10 - 13
common/services/xhMerchantAssetService.php

@@ -81,7 +81,6 @@ class xhMerchantAssetService
         switch ($capitalType) {
             //购买商品
             case $typeList['xhOrder']['id']:
-                $orderName = $order['bookName'];
                 $totalFee = $order['actPrice'];
                 $goodsList = xhOrderGoodsService::getAllByOrderId($orderId);
                 if (!empty($goodsList)) {
@@ -106,18 +105,16 @@ class xhMerchantAssetService
                 break;
         }
         self::updateByMerchantId($merchantId, $updateData);
-        //以下一定要排后面,否则数据不准确
-        if ($totalFee > 0) {
-            xhStatIncomeService::replace($merchantId, $totalFee, $order['payWay']);
-            xhStatIncomeMonthService::replace($merchantId, $totalFee, $order['payWay']);
-            /**收入来源资金增加**/
-            StatIncomeSourceService::replaceData([
-                'merchantId' => $order['merchantId'],
-                'sourceType' => $order['sourceType'],
-                'amount' => $order['actPrice'],
-                'payWay' => $order['payWay']
-            ]);
-        }
+
+        //数据统计,以下一定要排后面,否则数据不准确
+        xhStatIncomeService::replace($merchantId, $totalFee, $order['payWay']);
+        xhStatIncomeMonthService::replace($merchantId, $totalFee, $order['payWay']);
+        StatIncomeSourceService::replaceData([
+            'merchantId' => $order['merchantId'],
+            'sourceType' => $order['sourceType'],
+            'amount' => $order['actPrice'],
+            'payWay' => $order['payWay']
+        ]);
     }
 
     public static function add($data)

+ 3 - 0
common/services/xhStatIncomeMonthService.php

@@ -15,6 +15,9 @@ class xhStatIncomeMonthService
      */
     public static function replace($merchantId, $totalFee, $payWay)
     {
+        if ($totalFee <= 0) {
+            return true;
+        }
         $year = date("Y");
         $month = date("n");
         $time = date("Ym");

+ 117 - 113
common/services/xhStatIncomeService.php

@@ -9,117 +9,121 @@ use common\components\stringUtil;
 
 class xhStatIncomeService
 {
-	
-	/**
-	 * 添加与更新
-	 */
-	public static function replace($merchantId, $totalFee, $payWay)
-	{
-		$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 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];
+    }
+
 }