|
|
@@ -0,0 +1,84 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace biz\stat\classes;
|
|
|
+
|
|
|
+use biz\base\classes\BaseClass;
|
|
|
+use biz\stat\models\StatCg;
|
|
|
+use common\components\util;
|
|
|
+
|
|
|
+class StatKhCgMonthClass extends BaseClass
|
|
|
+{
|
|
|
+
|
|
|
+ public static $baseFile = '\biz\stat\models\StatKhCgMonth';
|
|
|
+
|
|
|
+ //每月客户采购统计 shish 20211012
|
|
|
+ public static function replace($order, $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 = $order->sjId ?? 0;
|
|
|
+ $shopId = $order->shopId ?? 0;
|
|
|
+ $customId = $order->customId ?? 0;
|
|
|
+ $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, 'year' => $year, 'month' => $month], true);
|
|
|
+ }
|
|
|
+ $id = $stat->id;
|
|
|
+ $amount = $order->actPrice ?? 0;
|
|
|
+ $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();
|
|
|
+ }
|
|
|
+
|
|
|
+ //客户退款
|
|
|
+ public static function refundReplace($order, $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 = $order['sjId'] ?? 0;
|
|
|
+ $shopId = $order['shopId'] ?? 0;
|
|
|
+ $customId = $order['customId'] ?? 0;
|
|
|
+ $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, 'year' => $year, 'month' => $month], true);
|
|
|
+ }
|
|
|
+ $id = $stat->id;
|
|
|
+ $unique = self::getLockById($id);
|
|
|
+
|
|
|
+ $num = $order['itemNum'] ?? 0;
|
|
|
+ $unitePrice = $order['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();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|