|
@@ -314,7 +314,7 @@ class CheckService extends Service
|
|
|
return [true,''];
|
|
|
}
|
|
|
|
|
|
- //todo
|
|
|
+ //分社订货合同
|
|
|
public function createPurchaseOrderSales($order){
|
|
|
//没有供应商 不创建合同
|
|
|
if(empty($order['supplier'])) return [true, ''];
|
|
@@ -337,6 +337,7 @@ class CheckService extends Service
|
|
|
->get()->toArray();
|
|
|
if(empty($product)) return [false, '采购订单产品数据不能为空'];
|
|
|
|
|
|
+ $time = time();
|
|
|
$depart_id = Depart::where('del_time',0)->where('parent_id',0)->where('is_main',1)->value('id');
|
|
|
$model = new SalesOrder();
|
|
|
$model->model_type = SalesOrder::Model_type_two;
|
|
@@ -348,6 +349,8 @@ class CheckService extends Service
|
|
|
$model->other_fee = $order['other_fee'];
|
|
|
$model->discount_fee = $order['discount_fee'];
|
|
|
$model->contract_fee = $order['purchase_total'];
|
|
|
+ $model->sign_time = $time;
|
|
|
+
|
|
|
$model->save();
|
|
|
$sales_order_id = $model->id;
|
|
|
|
|
@@ -355,7 +358,7 @@ class CheckService extends Service
|
|
|
$product_map = (new ProductService())->getProductDetail(array_column($product,'product_id'));
|
|
|
|
|
|
//获取产品采购使用金额
|
|
|
- $map = (new ProductService())->getProductPrice(array_column($product,'product_id'),1);
|
|
|
+ $map = (new ProductService())->getProductPrice(array_column($product,'product_id'));
|
|
|
//获取部门目前使用的分社价
|
|
|
$basic_type_id = Depart::where('id',$order['top_depart_id'])->value('basic_type_id');
|
|
|
//产品对应的分社价
|
|
@@ -382,13 +385,18 @@ class CheckService extends Service
|
|
|
'price' => $price,
|
|
|
'cost' => $tmp['cost'] ?? 0,
|
|
|
'retail_price' => $tmp['retail_price'] ?? 0,
|
|
|
+ 'final_amount' => $product_total,
|
|
|
];
|
|
|
}
|
|
|
$bool = SalesOrderProductInfo::insert($insert);
|
|
|
if(! $bool) return [false,'合同生成失败!'];
|
|
|
|
|
|
- //反写产品总计
|
|
|
- SalesOrder::where('id',$sales_order_id)->update(['product_total' => $product_total]);
|
|
|
+ //反写数据
|
|
|
+ $rate = ($product_total + $order['other_fee'] - $order['discount_fee']) / ($product_total + $order['other_fee'] ?? 1);
|
|
|
+ SalesOrder::where('id',$sales_order_id)->update([
|
|
|
+ 'product_total' => $product_total,
|
|
|
+ 'rate' =>$rate
|
|
|
+ ]);
|
|
|
return [true,''];
|
|
|
}
|
|
|
|