StatIncomeUsageMonthService.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace biz\stat\services;
  3. use biz\base\services\BaseService;
  4. use common\components\business;
  5. use common\components\validate;
  6. use Yii;
  7. class StatIncomeUsageMonthService extends BaseService
  8. {
  9. public static $baseFile = '\biz\stat\classes\StatIncomeUsageMonthClass';
  10. //添加更新记录 shish 2019.9.16
  11. public static function replaceData($data)
  12. {
  13. $valid = ['sourceType', 'amount', 'merchantId', 'payWay'];
  14. validate::easyCheck($valid, $data);
  15. $merchantId = $data['merchantId'];
  16. $usageId = $data['usageId'];
  17. $amount = $data['amount'];
  18. $data['year'] = isset($data['year']) ? $data['year'] : date("Y");
  19. $data['month'] = isset($data['month']) ? $data['month'] : date("n");
  20. $income = self::getByCondition(['merchantId' => $merchantId, 'year' => $data['year'], 'month' => $data['month'], 'usageId' => $usageId], true);
  21. if (empty($income)) {
  22. $income = self::add($data, true);
  23. } else {
  24. $income->amount += $amount;
  25. }
  26. $income = business::savePayWayAmount($income, $amount, $data['payWay']);
  27. $income->save();
  28. return true;
  29. }
  30. }