|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
|
+use App\Model\Construction;
|
|
|
+use App\Model\ConstructionProductInfo;
|
|
|
use App\Model\InOutRecord;
|
|
|
use App\Model\InvoiceOrder;
|
|
|
use App\Model\InvoiceOrderInfo;
|
|
@@ -27,7 +29,7 @@ class CheckService extends Service
|
|
|
self::two => '发货单',//确认后出库
|
|
|
self::three => '采购单',//确认后入库
|
|
|
self::four => '销售订单',
|
|
|
- self::five => '施工单',
|
|
|
+ self::five => '施工单',//确认后出库
|
|
|
];
|
|
|
|
|
|
//入库操作
|
|
@@ -49,12 +51,14 @@ class CheckService extends Service
|
|
|
self::two => 'confirmInvoiceOrder',
|
|
|
self::three => 'confirmPurchaseOrder',
|
|
|
self::four => 'confirmSalesOrder',
|
|
|
+ self::five => 'confirmConstruction',
|
|
|
];
|
|
|
|
|
|
//单据库存流水
|
|
|
public static $record = [
|
|
|
self::two => 'recordInvoiceOrder',
|
|
|
self::three => 'recordPurchaseOrder',
|
|
|
+ self::five => 'recordConstruction',
|
|
|
];
|
|
|
|
|
|
public function confirmInvoiceOrder($data){
|
|
@@ -76,14 +80,17 @@ class CheckService extends Service
|
|
|
->get()->toArray();
|
|
|
if(empty($result)) return [false,'发货单产品信息不存在或已被删除'];
|
|
|
$insert = [];
|
|
|
+ $time = time();
|
|
|
foreach ($result as $value){
|
|
|
if(isset($insert[$value['product_id']])){
|
|
|
- $insert[$value['product_id']]['number'] += $value['number'];
|
|
|
+ $insert[$value['product_id']]['number'] += -($value['number']);
|
|
|
}else{
|
|
|
$insert[$value['product_id']] = [
|
|
|
'product_id' => $value['product_id'],
|
|
|
- 'number' => $value['number'],
|
|
|
- 'order_type' => InvoiceOrder::prefix
|
|
|
+ 'number' => -($value['number']),
|
|
|
+ 'order_type' => InvoiceOrder::prefix,
|
|
|
+ 'order_number' => $order['order_number'],
|
|
|
+ 'crt_time' => $time
|
|
|
];
|
|
|
}
|
|
|
}
|
|
@@ -113,6 +120,7 @@ class CheckService extends Service
|
|
|
->get()->toArray();
|
|
|
if(empty($result)) return [false,'采购单产品信息不存在或已被删除'];
|
|
|
$insert = [];
|
|
|
+ $time = time();
|
|
|
foreach ($result as $value){
|
|
|
if(isset($insert[$value['product_id']])){
|
|
|
$insert[$value['product_id']]['number'] += $value['number'];
|
|
@@ -120,7 +128,9 @@ class CheckService extends Service
|
|
|
$insert[$value['product_id']] = [
|
|
|
'product_id' => $value['product_id'],
|
|
|
'number' => $value['number'],
|
|
|
- 'order_type' => PurchaseOrder::prefix
|
|
|
+ 'order_type' => PurchaseOrder::prefix,
|
|
|
+ 'order_number' => $order['order_number'],
|
|
|
+ 'crt_time' => $time
|
|
|
];
|
|
|
}
|
|
|
}
|
|
@@ -147,6 +157,46 @@ class CheckService extends Service
|
|
|
return [true,$model->toArray()];
|
|
|
}
|
|
|
|
|
|
+ public function confirmConstruction($data){
|
|
|
+ $model = Construction::where('id',$data['id'])
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->first();
|
|
|
+ if(empty($model)) return [false, '施工单不存在或已被删除'];
|
|
|
+ if($model->state != Construction::STATE_ZERO) return [false, '请确认施工单状态,操作失败'];
|
|
|
+
|
|
|
+ Construction::where('del_time',0)->where('id',$data['id'])
|
|
|
+ ->update(['state' => Construction::STATE_ONE]);
|
|
|
+
|
|
|
+ return [true, $model->toArray()];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function recordConstruction($data, $order){
|
|
|
+ $result = ConstructionProductInfo::where('del_time',0)
|
|
|
+ ->where('construction_id',$order['id'])
|
|
|
+ ->get()->toArray();
|
|
|
+ if(empty($result)) return [false,'施工单产品信息不存在或已被删除'];
|
|
|
+ $insert = [];
|
|
|
+ $time = time();
|
|
|
+ foreach ($result as $value){
|
|
|
+ if(isset($insert[$value['product_id']])){
|
|
|
+ $insert[$value['product_id']]['number'] += -($value['number']);
|
|
|
+ }else{
|
|
|
+ $insert[$value['product_id']] = [
|
|
|
+ 'product_id' => $value['product_id'],
|
|
|
+ 'number' => -($value['number']),
|
|
|
+ 'order_type' => Construction::$prefix[$order['model_type']] ?? '',
|
|
|
+ 'order_number' => $order['order_number'],
|
|
|
+ 'crt_time' => $time
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $insert = array_values($insert);
|
|
|
+ $bool = InOutRecord::insert($insert);
|
|
|
+ if(! $bool) return [false,'流水写入失败'];
|
|
|
+
|
|
|
+ return [true,''];
|
|
|
+ }
|
|
|
+
|
|
|
public function checkAll($data,$user){
|
|
|
if(empty($data['id']) || empty($data['opt_case'])) return [false,'必传参数不能为空或者参数值错误!'];
|
|
|
|