| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- use biz\stat\models\StatCg;
- use common\components\util;
- class StatItemClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatItem';
- //预订单到货之后退货数
- public static function ghsBookOrderRefundNum($order, $info, $num, $date = null)
- {
- $sjId = $order->sjId ?? 0;
- $shopId = $order->shopId ?? 0;
- $productId = $info->productId ?? 0;
- $time = $date == null ? date('Ymd') : $date;
- $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'itemId' => $productId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'itemId' => $productId, 'time' => $time], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- $currentNum = bcadd($unique->refundNum, $num, 2);
- $unique->refundNum = $currentNum;
- $unique->save();
- StatItemMonthClass::ghsBookOrderRefundNum($order, $info, $num, $time);
- }
- //每日花材统计 ssh 2021012
- public static function replace($item, $date = null)
- {
- $sjId = $item['sjId'] ?? 0;
- $mainId = $item['mainId'] ?? 0;
- $itemId = $item['itemId'] ?? 0;
- $time = $date == null ? date('Ymd') : $date;
- $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'itemId' => $itemId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'itemId' => $itemId, 'time' => $time], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- $amount = $item['price'] ?? 0;
- $num = $item['num'] ?? 0;
- $currentNum = bcadd($unique->num, $num, 2);
- $unique->num = $currentNum;
- $currentAmount = bcadd($unique->amount, $amount, 2);
- $unique->amount = $currentAmount;
- $unique->save();
- StatItemMonthClass::replace($item, $time);
- }
- //退款花材
- public static function refundReplace($item, $date = null)
- {
- $mainId = $item['mainId'] ?? 0;
- $productId = $item['productId'] ?? 0;
- $time = $date == null ? date('Ymd') : $date;
- $stat = self::getByCondition(['mainId' => $mainId, 'itemId' => $productId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['mainId' => $mainId, 'itemId' => $productId, 'time' => $time], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- $num = $item['itemNum'] ?? 0;
- $unitePrice = $item['itemPrice'] ?? 0;
- $price = bcmul($unitePrice, $num, 2);
- $currentRefundNum = bcadd($unique->refundNum, $num, 2);
- $currentRefundAmount = bcadd($unique->refundAmount, $price, 2);
- $unique->refundNum = $currentRefundNum;
- $unique->refundAmount = $currentRefundAmount;
- $unique->save();
- StatItemMonthClass::refundReplace($item, $time);
- }
- }
|