<?php

namespace app\admin\service\order;

use app\model\GoodsRunning;
use app\model\OrderSheet;
use support\Log;

class OrderSheetService
{
    public static function addGoodsSales($orderId)
    {
        Log::info('开始加销售量', ['order_id' => $orderId]);
        try {
            $sheets = OrderSheet::where('join_sheet_order_id', $orderId)->select('join_sheet_goods_id', 'order_sheet_num')->get()->toArray();
            foreach ($sheets as $sheet) {
                GoodsRunning::where('join_running_goods_id', $sheet['join_sheet_goods_id'])->increment('goods_running_sale', $sheet['order_sheet_num']);
            }
        } catch (\Exception $e) {
            Log::error("加销售量失败", ['msg' => $e->getMessage(), 'order_id' => $orderId]);
        }
    }
}