<?php
declare(strict_types=1);
namespace app\api\service;

use app\common\model\ShopList;
use app\common\model\StockConfig;
use app\common\model\ProductConfig;
use app\common\model\StockDetail;
/**
 * 出入库
 */
class StockService {
      //出入库：  id 库存的id
      public static function setGoOutStock(int $uid, array $data): array
      {     
            $result = [];
            foreach ($data['variety'] as $item) 
            {
                  if(count($item) != 4 || empty(floatval($item['num'])))  throw new \Exception('参数有误！');
                  $weight = ($data['type']== '1') ? -$item['num']: $item['num'];
                
                  //根据品种扣除库存
                  $stock = StockDetail::setStockConfigNum((int)$item['variety_id'], (string)$weight, $data['type_id']);

                  //记录数据
                  $result[] = [
                        'user_id'         => $uid, 
                        'type_id'         => $data['type_id'],
                        'type'            => $data['type'],
                        'variety_id'      => $item['variety_id'],
                        'change'          => $item['num'],
                        'after'           => $stock,
                        'remark'          => $item['remark']
                  ];
            }
            return $result;
      }


   


   
}