|
@@ -98,6 +98,9 @@ class ConstructionService extends Service
|
|
|
];
|
|
|
}
|
|
|
ConstructionProductInfo::insert($insert);
|
|
|
+
|
|
|
+ //锁定库存
|
|
|
+ ProductInventoryService::changeLockNumber($msg[0],$msg[1]);
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
@@ -188,6 +191,9 @@ class ConstructionService extends Service
|
|
|
];
|
|
|
}
|
|
|
ConstructionProductInfo::insert($insert);
|
|
|
+
|
|
|
+ //锁定库存
|
|
|
+ ProductInventoryService::changeLockNumber($msg[0]);
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
@@ -202,6 +208,7 @@ class ConstructionService extends Service
|
|
|
public function constructionDel($data){
|
|
|
if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
|
|
|
+ $product_save = $this->getSaveDetail($data['id']);
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
|
|
@@ -215,6 +222,9 @@ class ConstructionService extends Service
|
|
|
->where('construction_id',$data['id'])
|
|
|
->update(['del_time' => time()]);
|
|
|
|
|
|
+ //锁定库存释放
|
|
|
+ ProductInventoryService::changeLockNumber([],$product_save);
|
|
|
+
|
|
|
DB::commit();
|
|
|
}catch (\Exception $exception){
|
|
|
DB::rollBack();
|
|
@@ -326,15 +336,7 @@ class ConstructionService extends Service
|
|
|
if(empty($sale)) return [false,'合同不存在或已被删除'];
|
|
|
if($sale['state'] < SalesOrder::State_two) return [false,'合同未派单,不允许新建施工单'];
|
|
|
if(empty($data['product'])) return [false,'请选择产品'];
|
|
|
-// foreach ($data['product'] as $value){
|
|
|
-// if(empty($value['number'])) return [false,'产品数量不能为空'];
|
|
|
-// $res = $this->checkNumber($value['number']);
|
|
|
-// if(! $res) return [false,'请输入正确的产品数量'];
|
|
|
-//
|
|
|
-// if(empty($value['retail_price'])) return [false,'产品价格不能为空'];
|
|
|
-// $res = $this->checkNumber($value['retail_price']);
|
|
|
-// if(! $res) return [false,'产品价格请输入不超过两位小数并且大于0的数值'];
|
|
|
-// }
|
|
|
+
|
|
|
if(! empty($data['construction_fee'])){
|
|
|
$res = $this->checkNumber($data['construction_fee']);
|
|
|
if(! $res) return [false,'施工费用请输入不超过两位小数并且大于0的数值'];
|
|
@@ -358,14 +360,35 @@ class ConstructionService extends Service
|
|
|
if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
|
|
|
$data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
|
|
|
|
|
|
+ $product_submit = $product_save = [];
|
|
|
+ foreach ($data['product'] as $value){
|
|
|
+ if(empty($value['number'])) return [false,'产品数量不能为空'];
|
|
|
+ $res = $this->checkNumber($value['number']);
|
|
|
+ if(! $res) return [false,'请输入正确的产品数量'];
|
|
|
+
|
|
|
+ if(isset($product_submit[$value['product_id']])){
|
|
|
+ $product_submit[$value['product_id']] += $value['number'];
|
|
|
+ }else{
|
|
|
+ $product_submit[$value['product_id']] = $value['number'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $order_number = "";
|
|
|
+ if(! $is_add) $order_number = $data['order_number'];
|
|
|
+ list($status,$msg) = (new ProductInventoryService())->compareStock(array_keys($product_submit), [
|
|
|
+ 'order_number' => $order_number,
|
|
|
+ 'product' => $product_submit
|
|
|
+ ]);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
if($is_add){
|
|
|
$bool = Construction::where('del_time',0)->where('order_number',$data['order_number'])->exists();
|
|
|
if($bool) return [false,'工单编号已存在,请重新获取'];
|
|
|
}else{
|
|
|
if(empty($data['id'])) return [false,'ID不能为空'];
|
|
|
+ $product_save = $this->getSaveDetail($data['id']);
|
|
|
}
|
|
|
|
|
|
- return [true, $data];
|
|
|
+ return [true, [$product_submit, $product_save]];
|
|
|
}
|
|
|
|
|
|
public function fillData($data){
|
|
@@ -411,4 +434,20 @@ class ConstructionService extends Service
|
|
|
|
|
|
return [true,['order_number' => $order_number]];
|
|
|
}
|
|
|
+
|
|
|
+ public function getSaveDetail($id){
|
|
|
+ $product_save = [];
|
|
|
+ $sub = ConstructionProductInfo::where('construction_id',$id)
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->get()->toArray();
|
|
|
+ foreach ($sub as $value){
|
|
|
+ if(isset($product_save[$value['product_id']])){
|
|
|
+ $product_save[$value['product_id']] += $value['number'];
|
|
|
+ }else{
|
|
|
+ $product_save[$value['product_id']] = $value['number'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $product_save;
|
|
|
+ }
|
|
|
}
|