|
|
@@ -1,73 +0,0 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-namespace biz\stat\services;
|
|
|
-
|
|
|
-use biz\base\services\BaseService;
|
|
|
-use biz\goods\services\UsageRelationService;
|
|
|
-use common\components\business;
|
|
|
-use common\components\stringUtil;
|
|
|
-use common\components\validate;
|
|
|
-use common\components\util;
|
|
|
-use Yii;
|
|
|
-
|
|
|
-class StatIncomeUsageService extends BaseService
|
|
|
-{
|
|
|
-
|
|
|
- public static $baseFile = '\biz\stat\classes\StatIncomeUsageClass';
|
|
|
-
|
|
|
- //添加更新记录 shish 2010.8.20
|
|
|
- public static function replaceData($data)
|
|
|
- {
|
|
|
- $valid = ['usageId', 'amount', 'merchantId', 'payWay'];
|
|
|
- validate::easyCheck($valid, $data);
|
|
|
- $time = date("Ymd");
|
|
|
- if (isset($data['time'])) {
|
|
|
- //如果传time参数必须是时间戳
|
|
|
- if (strtotime(date('Y-m-d H:i:s', $data['time'])) != $data['time']) {
|
|
|
- util::fail('time不是时间戳');
|
|
|
- }
|
|
|
- $time = date("Ymd", $data['time']);
|
|
|
- $data['time'] = $time;
|
|
|
- }
|
|
|
- $merchantId = $data['merchantId'];
|
|
|
- $usageId = $data['usageId'];
|
|
|
- $amount = $data['amount'];
|
|
|
- $payWay = $data['payWay'];
|
|
|
- $income = self::getByCondition(['merchantId' => $merchantId, 'time' => $time, 'usageId' => $usageId], true);
|
|
|
- if (empty($income)) {
|
|
|
- $income = self::add($data, true);
|
|
|
- } else {
|
|
|
- $income->amount += $data['amount'];
|
|
|
- }
|
|
|
- business::savePayWayAmount($income, $amount, $payWay);
|
|
|
-
|
|
|
- /**每个月增加**/
|
|
|
- StatIncomeUsageMonthService::replaceData($data);
|
|
|
-
|
|
|
- $income->save();
|
|
|
- }
|
|
|
-
|
|
|
- public static function getLatestIncome($start, $end)
|
|
|
- {
|
|
|
- $merchantId = Yii::$app->params['merchantId'];
|
|
|
- $list = self::getAllList('usageId,amount', ['merchantId' => $merchantId, 'time' => ['between', [$start, $end]]], 'time asc');
|
|
|
- $totalAmount = 0;
|
|
|
- $usageList = UsageRelationService::getMyUsage();
|
|
|
- $data = [];
|
|
|
- foreach ($usageList as $usageId => $category) {
|
|
|
- $data[$usageId]['name'] = $category['showName'];
|
|
|
- $data[$usageId]['value'] = 0;
|
|
|
- }
|
|
|
- if (!empty($list)) {
|
|
|
- foreach ($list as $val) {
|
|
|
- $usageId = $val['usageId'];
|
|
|
- $amount = $val['amount'];
|
|
|
- $data[$usageId]['value'] = stringUtil::calcAdd($data[$usageId]['value'], $amount);
|
|
|
- $totalAmount = stringUtil::calcAdd($totalAmount, $amount);
|
|
|
- }
|
|
|
- }
|
|
|
- $usageName = array_column($usageList, 'showName');
|
|
|
- return ['data' => array_values($data), 'usageName' => $usageName, 'totalAmount' => $totalAmount];
|
|
|
- }
|
|
|
-
|
|
|
-}
|