ソースを参照

上个月收入

shish 6 年 前
コミット
9a4f29225c

+ 11 - 3
app/business/controllers/ConsoleController.php

@@ -3,6 +3,7 @@
 namespace business\controllers;
 
 use biz\merchant\services\MerchantAssetService;
+use biz\stat\services\StatIncomeMonthService;
 use biz\stat\services\StatIncomeService;
 use biz\stat\services\StatOrderService;
 use biz\stat\services\StatUserService;
@@ -32,12 +33,19 @@ class ConsoleController extends BaseController
 		//今天收入
 		$incomeData = StatIncomeService::getTodayNum($this->merchantId);
 		$todayIncome = isset($incomeData['amount']) ? $incomeData['amount'] : 0;
-		
 		$todayData = ['visit' => $todayVisit, 'fans' => $todayFansNum, 'user' => $todayUserNum, 'income' => $todayIncome, 'order' => $todayOrder];
+		
+		//当月的收入
+		$currentMonthIncome = StatIncomeMonthService::getCurrentMonthIncome($this->merchantId);
+		//上个月收入
+		$previousMonthIncome = StatIncomeMonthService::getPreviousMonthIncome($this->merchantId);
+		//最近7天收入变化趋势
+		$latestIncome = StatIncomeService::getLatestSevenDay($this->merchantId);
 		$incomeStat = [
-			'month' => 1999,
+			'month' => $currentMonthIncome,
 			'week' => 999,
-			'list' => ['7.1' => 100, '7.2' => 200, '7.3' => 300, '7.4' => 400, '7.5' => 500],
+			'previousMonth' => $previousMonthIncome,
+			'list' => $latestIncome,
 		];
 		$visitStat = [
 			'month' => 1999,

+ 19 - 0
biz/stat/services/StatIncomeMonthService.php

@@ -3,6 +3,7 @@
 namespace biz\stat\services;
 
 use biz\base\services\BaseService;
+use biz\stat\classes\StatIncomeMonthClass;
 use Yii;
 
 class StatIncomeMonthService extends BaseService
@@ -10,4 +11,22 @@ class StatIncomeMonthService extends BaseService
 	
 	public static $baseFile = '\biz\stat\classes\StatIncomeMonthClass';
 	
+	//获取当前月份的收入 shish 2020.2.2
+	public static function getCurrentMonthIncome($merchantId)
+	{
+		$month = date("Ym");
+		$return = StatIncomeMonthClass::getByCondition(['merchantId' => $merchantId, 'time' => $month]);
+		$income = isset($return['amount']) ? $return['amount'] : 0;
+		return $income;
+	}
+
+	//上个月收入 shish 2020.2.2
+	public static function getPreviousMonthIncome($merchantId)
+	{
+		$month = date("Ym", mktime(0, 0, 0, date("m") - 1, 1, date("Y")));
+		$return = StatIncomeMonthClass::getByCondition(['merchantId' => $merchantId, 'time' => $month]);
+		$income = isset($return['amount']) ? $return['amount'] : 0;
+		return $income;
+	}
+
 }

+ 19 - 0
biz/stat/services/StatIncomeService.php

@@ -4,6 +4,7 @@ namespace biz\stat\services;
 
 use biz\base\services\BaseService;
 use biz\stat\classes\StatIncomeClass;
+use common\components\dateUtil;
 use common\components\util;
 use Yii;
 
@@ -40,4 +41,22 @@ class StatIncomeService extends BaseService
 		return $list;
 	}
 	
+	//最近7天收入情况 shish 2020.2.2
+	public static function getLatestSevenDay($merchantId)
+	{
+		$return = dateUtil::getDate(1);
+		$start = $return[0];
+		$end = $return[1];
+		$list = self::getLatestIncome($start, $end, $merchantId);
+		$data = [];
+		if (!empty($list)) {
+			foreach ($list as $key => $val) {
+				$date = $val['time'];
+				$income = $val['amount'];
+				$data[$date] = $income;
+			}
+		}
+		return $data;
+	}
+
 }

+ 3 - 1
biz/stat/services/StatOrderMonthService.php

@@ -7,7 +7,9 @@ use Yii;
 
 class StatOrderMonthService extends BaseService
 {
-	
+
 	public static $baseFile = '\biz\stat\classes\StatOrderMonthClass';
+
+
 	
 }