| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- class StatKhCgClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatKhCg';
- //预订单数量减少
- public static function ghsBookOrderRefundNum($order, $num, $date = null)
- {
- $sjId = $order->sjId ?? 0;
- $shopId = $order->shopId ?? 0;
- $customId = $order->customId ?? 0;
- $time = $date == null ? date('Ymd') : $date;
- $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- $currentNum = bcadd($unique->refundNum, $num, 2);
- $unique->refundNum = $currentNum;
- $unique->save();
- StatKhCgMonthClass::ghsBookOrderRefundNum($order, $num, $time);
- }
- //供货商预订单退款,客户采购金额减少
- public static function ghsBookOrderChange($add, $order, $amount, $date = null)
- {
- $sjId = $order->sjId ?? 0;
- $shopId = $order->shopId ?? 0;
- $customId = $order->customId ?? 0;
- $time = $date == null ? date('Ymd') : $date;
- $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- if ($add == true) {
- $currentAmount = bcadd($unique->amount, $amount, 2);
- $unique->amount = $currentAmount;
- } else {
- $currentAmount = bcadd($unique->refundAmount, $amount, 2);
- $unique->refundAmount = $currentAmount;
- }
- $unique->save();
- StatKhCgMonthClass::ghsBookOrderChange($add, $order, $amount, $time);
- }
- //客户采购统计 ssh 2021012
- public static function replace($order, $amount, $date = null)
- {
- $sjId = $order->sjId ?? 0;
- $shopId = $order->shopId ?? 0;
- $customId = $order->customId ?? 0;
- $time = $date == null ? date('Ymd') : $date;
- $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- $num = $order->itemNum ?? 0;
- $currentNum = bcadd($unique->num, $num, 2);
- $unique->num = $currentNum;
- $currentAmount = bcadd($unique->amount, $amount, 2);
- $unique->amount = $currentAmount;
- $unique->save();
- StatKhCgMonthClass::replace($order, $amount, $time);
- }
- //客户退款统计
- public static function refundReplace($order, $date = null)
- {
- $sjId = $order->sjId ?? 0;
- $shopId = $order->shopId ?? 0;
- $customId = $order->customId ?? 0;
- $time = $date == null ? date('Ymd') : $date;
- $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- $num = $order->itemNum ?? 0;
- $refundPrice = $order->refundPrice ?? 0;
- $currentRefundNum = bcadd($unique->refundNum, $num, 2);
- $currentRefundAmount = bcadd($unique->refundAmount, $refundPrice, 2);
- $unique->refundNum = $currentRefundNum;
- $unique->refundAmount = $currentRefundAmount;
- $unique->save();
- StatKhCgMonthClass::refundReplace($order, $time);
- }
- }
|