value('customer_id'); foreach ($data['variety'] as $item) { if(count($item) != 6 || empty(floatval($item['num']))) throw new \Exception('参数有误!'); $specs = ProductConfig::where('id', $item['spec_id'])->field('weight,box_id')->find(); if(!$specs) throw new \Exception('参数有误!'); $weight = bcmul((string)$specs->weight, $item['num'], 2); $result[] = [ 'user_id' => $uid, 'customer_id' => $customer_id, 'shop_id' => $data['shop_id'], 'plat_id' => $data['plat_id'], 'variety_id' => $item['variety_id'], 'spec_id' => $item['spec_id'], 'num' => $item['num'], 'weigh' => $weight, 'price' => $item['price'], 'total_price' => bcmul($item['price'], $item['num'], 2) ]; //根据品种扣除库存 $varietyNum = StockDetail::setStockConfigNum((int)$item['variety_id'], (string)-$weight, StockConfig::VarietyName); $stockData[] = [ 'user_id' => $uid, 'type_id' => StockConfig::VarietyName, 'type' => 1, 'variety_id' => $item['variety_id'], 'change' => -$weight, 'after' => $varietyNum, 'remark' => '录入出库' ]; //根据规格扣除包装箱 $boxNum = StockDetail::setStockConfigNum($specs->box_id, (string)-$item['num'], StockConfig::PackingBox); $stockData[] = [ 'user_id' => $uid, 'type_id' => StockConfig::PackingBox, 'type' => 1, 'variety_id' => $item['variety_id'], 'change' => -$item['num'], 'after' => $boxNum, 'remark' => '录入出库' ]; } return [$result, $stockData]; } public static function getDeliveryEdit(int $user_id, array $data) { //查询发货记录 $delivery = ShopDelivery::where('user_id', $user_id)->where('id', $data['ids'])->find(); if(!$delivery) throw new \Exception('参数有误!'); //判断是否当天 if(substr($delivery->createtime, 0, 10) != date('Y-m-d')) throw new \Exception('只能修改当日发货记录!'); //修改库存 $specs = ProductConfig::where('id', $delivery->spec_id)->field('weight,box_id')->find(); if(!$specs) throw new \Exception('参数有误!'); //根据品种扣除库存 $weight = bcmul((string)$specs->weight, $data['num'], 2); //总重 //扣除品种 StockDetail::setStockConfigNum($delivery->variety_id, bcsub($delivery->weigh, $weight, 2), StockConfig::VarietyName); //根据规格扣除包装箱 StockDetail::setStockConfigNum($specs->box_id, bcsub((string)$delivery->num, $data['num'], 2), StockConfig::PackingBox); //修改数量 $price = bcdiv($delivery->total_price, (string)$delivery->num, 2); //单价 $delivery->weigh = $weight; //总重 $delivery->num = $data['num']; $delivery->total_price = bcmul($price, $data['num'], 2); return $delivery->save(); } //删除 public static function getDeliveryDel(int $user_id, array $data) { //查询发货记录 $delivery = ShopDelivery::where('user_id', $user_id)->where('id', $data['ids'])->find(); if(!$delivery) throw new \Exception('参数有误!'); //判断是否当天 if(substr($delivery->createtime, 0, 10) != date('Y-m-d')) throw new \Exception('只能修改当日发货记录!'); //修改库存 $box_id = ProductConfig::where('id', $delivery->spec_id)->value('box_id'); if(!$box_id) throw new \Exception('参数有误!'); //扣除品种 StockDetail::setStockConfigNum($delivery->variety_id, $delivery->weigh, StockConfig::VarietyName); //根据规格扣除包装箱 StockDetail::setStockConfigNum($box_id, (string)$delivery->num, StockConfig::PackingBox); //删除 return $delivery->delete(); } }