|
@@ -354,11 +354,102 @@ class OutBoundOrderService extends Service
|
|
|
|
|
|
// 合同 出库
|
|
|
$return = [];
|
|
|
- if($data['type'] == OutBoundOrder::out_type_one) $return = $this->getSalesProduct($data, $user);
|
|
|
+ if($data['type'] == OutBoundOrder::out_type_one) $return = $this->getSalesProductForList($data, $user);
|
|
|
|
|
|
return [true, $return];
|
|
|
}
|
|
|
|
|
|
+ public function getSalesProductForList($data, $user){
|
|
|
+ $return = [];
|
|
|
+ $data_id = $data['data_id'];
|
|
|
+ $out_bound_id = $data['out_bound_id'] ?? 0;
|
|
|
+ $product = SalesOrderProductInfo::where('del_time',0)
|
|
|
+ ->where('sales_order_id', $data_id)
|
|
|
+ ->select('product_id', 'number', 'final_amount','price')
|
|
|
+ ->get()->toArray();
|
|
|
+ $map = (new ProductService())->getProductDetail(array_column($product,'product_id'));
|
|
|
+
|
|
|
+ //合同出库产品
|
|
|
+ $product_map = [];
|
|
|
+ $save = OutBoundOrderInfo::where('del_time',0)
|
|
|
+ ->where('type', $data['type'])
|
|
|
+ ->where('data_id', $data_id)
|
|
|
+ ->when(! empty($out_bound_id), function ($query) use ($out_bound_id) {
|
|
|
+ return $query->where('out_bound_id', '<>', $out_bound_id);
|
|
|
+ })
|
|
|
+ ->select('product_id', 'number', 'final_amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ foreach ($save as $value){
|
|
|
+ if(isset($product_map[$value['product_id']])){
|
|
|
+ $number = bcadd($value['number'], $product_map[$value['product_id']]);
|
|
|
+ $product_map[$value['product_id']] = $number;
|
|
|
+ }else{
|
|
|
+ $product_map[$value['product_id']] = $value['number'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //合同退货产品
|
|
|
+ $product_map2 = [];
|
|
|
+ $return_id = ReturnExchangeOrder::where('del_time',0)
|
|
|
+ ->where('type', ReturnExchangeOrder::Order_type)
|
|
|
+ ->where('model_type', ReturnExchangeOrder::Model_type_one)
|
|
|
+ ->where('data_id', $data_id)
|
|
|
+ ->select('id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $save2 = ReturnExchangeOrderProductInfo::where('del_time',0)
|
|
|
+ ->whereIn('return_exchange_id', array_column($return_id,'id'))
|
|
|
+ ->where('return_or_exchange',ReturnExchangeOrderProductInfo::type_one)
|
|
|
+ ->select('product_id', 'number', 'final_amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ foreach ($save2 as $value){
|
|
|
+ if(isset($product_map2[$value['product_id']])){
|
|
|
+ $number = bcadd($value['number'], $product_map2[$value['product_id']]);
|
|
|
+ $product_map2[$value['product_id']] = $number;
|
|
|
+ }else{
|
|
|
+ $product_map2[$value['product_id']] = $value['number'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($product as $value){
|
|
|
+ //合同出库产品
|
|
|
+ $p1 = $product_map[$value['product_id']] ?? 0;
|
|
|
+ //合同退货产品
|
|
|
+ $p2 = $product_map2[$value['product_id']] ?? 0;
|
|
|
+ $number = bcsub(bcsub($value['number'], $p1), $p2);
|
|
|
+
|
|
|
+ if($p1 > 0) {
|
|
|
+ $state = 2;
|
|
|
+ $state_title = "已出库";
|
|
|
+ }else{
|
|
|
+ if($p2 > 0){
|
|
|
+ $state_title = "已退货";
|
|
|
+ $state = 1;
|
|
|
+ }else{
|
|
|
+ $state_title = "未出库";
|
|
|
+ $state = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $tmp = $map[$value['product_id']] ?? [];
|
|
|
+ $return[] = [
|
|
|
+ 'number' => $number, //可出数量
|
|
|
+ 'out_number' => $p1, //已出库数量
|
|
|
+ 'return_number' => $p2, //已退货数量
|
|
|
+ 'state' => $state,
|
|
|
+ 'state_title' => $state_title,
|
|
|
+ 'price' => $value['price'],
|
|
|
+ 'final_amount' => bcmul($value['price'], $number,2),
|
|
|
+ 'product_id' => $value['product_id'],
|
|
|
+ 'title' => $tmp['title'] ?? "",
|
|
|
+ 'code' => $tmp['code'] ?? "",
|
|
|
+ 'size' => $tmp['size'] ?? "",
|
|
|
+ 'unit' => $tmp['unit'] ?? "",
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $return;
|
|
|
+ }
|
|
|
+
|
|
|
public function getSalesProduct($data, $user){
|
|
|
$return = [];
|
|
|
$data_id = $data['data_id'];
|