| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- use common\components\dict;
- use common\components\util;
- class StatRefundMonthClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatRefundMonth';
- //退款统计 ssh 20210827
- public static function replace($main, $shop, $payWay, $amount, $date = null)
- {
- if ($date == null) {
- $time = date('Ym');
- $year = date('Y');
- $month = date('m');
- } else {
- $timestamp = strtotime($date);
- $time = date('Ym', $timestamp);
- $year = date('Y', $timestamp);
- $month = date('m', $timestamp);
- }
- $sjId = $shop->sjId;
- $mainId = $main->id ?? 0;
- $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- $currentAmount = bcadd($unique->amount, $amount, 2);
- $unique->amount = $currentAmount;
- $unique->totalAmount = $main->totalRefund;
- $unique->num += 1;
- $map = dict::getDict('payWay');
- switch ($payWay) {
- case $map['wxPay']:
- $current = bcadd($unique->wx, $amount, 2);
- $unique->wx = $current;
- break;
- case $map['alipay']:
- $current = bcadd($unique->alipay, $amount, 2);
- $unique->alipay = $current;
- break;
- case $map['balancePay']:
- $current = bcadd($unique->balance, $amount, 2);
- $unique->balance = $current;
- break;
- case $map['debtPay']:
- $current = bcadd($unique->debt, $amount, 2);
- $unique->debt = $current;
- break;
- case $map['cash']:
- $current = bcadd($unique->cash, $amount, 2);
- $unique->cash = $current;
- break;
- case $map['bankCard']:
- $current = bcadd($unique->bank, $amount, 2);
- $unique->bank = $current;
- break;
- default:
- }
- $unique->save();
- }
- }
|