| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- use biz\stat\models\StatRefund;
- use common\components\dict;
- class StatRefundClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatRefund';
- //获取总和 ssh 20210829
- public static function getSum($where)
- {
- $amount = self::sum($where, 'amount');
- return empty($amount) ? 0 : $amount;
- }
- //退款统计 ssh 20210827
- public static function replace($main, $shop, $payWay, $amount, $date = null)
- {
- $sjId = $shop->sjId ?? 0;
- $mainId = $main->id ?? 0;
- $time = $date == null ? date('Ymd') : $date;
- $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time, 'num' => 0], 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();
- StatRefundMonthClass::replace($main, $shop, $payWay, $amount, $time);
- }
- }
|