| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace console\controllers;
- use biz\shop\classes\ShopClass;
- use biz\stat\classes\StatKdClass;
- use biz\stat\classes\StatRefundClass;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\models\Order;
- use bizGhs\order\models\RefundOrder;
- use yii\console\Controller;
- use Yii;
- class StatKdController extends Controller
- {
- //销售数据更新 ./yii stat-kd/update
- public function actionUpdate()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $sql = 'TRUNCATE `xhStatKd`;TRUNCATE `xhStatKdMonth`;';
- Yii::$app->db->createCommand($sql)->execute();
- $query = new \yii\db\Query();
- $query->from(Order::tableName());
- foreach ($query->batch() as $batch) {
- foreach ($batch as $order) {
- $status = $order['status'] ?? 0;
- if ($status == 1 || $status == 5) {
- continue;
- }
- $payWay = $order['payWay'] ?? 0;
- $amount = $order['actPrice'] ?? 0;
- $refundPrice = $order['refundPrice'] ?? 0;
- if ($refundPrice > 0) {
- $amount = bcadd($amount, $refundPrice, 2);
- }
- $shopId = $order['shopId'] ?? 0;
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- continue;
- }
- $date = date('Ymd', strtotime($order['addTime']));
- //各渠道收入金额统计
- StatKdClass::replace($shop, $amount, $payWay, $date);
- }
- }
- $sql = 'TRUNCATE `xhStatRefund`;TRUNCATE `xhStatRefundMonth`;';
- Yii::$app->db->createCommand($sql)->execute();
- $query = new \yii\db\Query();
- $query->from(RefundOrder::tableName());
- foreach ($query->batch() as $batch) {
- foreach ($batch as $refund) {
- $relateOrderSn = $refund['relateOrderSn'] ?? '';
- $order = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
- $payWay = $order->payWay ?? 0;
- $shopId = $refund['shopId'] ?? 0;
- $shop = ShopClass::getLockById($shopId);
- $amount = $refund['refundPrice'] ?? 0;
- $date = date('Ymd', strtotime($refund['addTime']));
- StatRefundClass::replace($shop, $payWay, $amount, $date);
- }
- }
- }
- }
|