|
@@ -5,12 +5,14 @@ namespace App\Service;
|
|
|
use App\Model\BasicType;
|
|
|
use App\Model\Construction;
|
|
|
use App\Model\ConstructionProductInfo;
|
|
|
+use App\Model\Depart;
|
|
|
use App\Model\InOutRecord;
|
|
|
use App\Model\InvoiceOrder;
|
|
|
use App\Model\InvoiceOrderInfo;
|
|
|
use App\Model\Product;
|
|
|
use App\Model\ProductCategory;
|
|
|
use App\Model\ProductInventory;
|
|
|
+use App\Model\ProductInventorySet;
|
|
|
use App\Model\PurchaseOrder;
|
|
|
use App\Model\ReturnExchangeOrder;
|
|
|
use App\Model\SalesOrder;
|
|
@@ -91,14 +93,15 @@ class ProductInventoryService extends Service
|
|
|
}
|
|
|
|
|
|
//更新锁定库存
|
|
|
- //第一个数组 (提交的数据) 第二个数组(保存过的数据)
|
|
|
- public static function changeLockNumber($submit_total = [], $save_total = []){
|
|
|
+ //$user 当前登录人的信息
|
|
|
+ //$submit_total (提交的数据) $save_total(保存过的数据)
|
|
|
+ public static function changeLockNumber($user, $submit_total = [], $save_total = []){
|
|
|
if(empty($submit_total) && empty($save_total)) return;
|
|
|
|
|
|
- $setting_map = Setting::where('setting_name','lock_number')
|
|
|
- ->pluck('setting_value','setting_name')
|
|
|
- ->toArray();
|
|
|
- if(empty($setting_map['lock_number'])) return; //是否使用锁定库存
|
|
|
+ //是否使用锁定库存校验 默认使用
|
|
|
+ $depart = array_shift($user['rule_depart']);
|
|
|
+ $is_stock = empty($depart['is_stock']) ? 1 : $depart['is_stock'];
|
|
|
+ if($is_stock == ProductInventorySet::type_two) return;
|
|
|
|
|
|
//产品数扣减
|
|
|
if(! empty($save_total)){
|
|
@@ -121,15 +124,14 @@ class ProductInventoryService extends Service
|
|
|
}
|
|
|
|
|
|
//比较库存
|
|
|
- public static function compareStock($product_id = [],$product_submit = [], $product_save = []){
|
|
|
+ public static function compareStock($user, $product_id = [],$product_submit = [], $product_save = []){
|
|
|
if(empty($product_id) || empty($product_submit)) return [false,'比较参数不能为空'];
|
|
|
|
|
|
//库存
|
|
|
$array = ProductInventory::whereIn('product_id', $product_id)
|
|
|
- ->where('number','>',0)
|
|
|
->select('id','product_id','number','crt_time','lock_number','storehouse_id')
|
|
|
->get()->toArray();
|
|
|
- if(empty($array)) return [false,'未找到产品库存数据'];
|
|
|
+ if(empty($array)) return [false,'产品库存数据不存在'];
|
|
|
$stock = [];
|
|
|
foreach ($array as $value){
|
|
|
$key = $value['product_id'] . ',' . $value['storehouse_id'];
|
|
@@ -139,26 +141,28 @@ class ProductInventoryService extends Service
|
|
|
$pro = Product::whereIn('id',$product_id)
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
|
- $setting_map = Setting::where('setting_name','lock_number')
|
|
|
- ->pluck('setting_value','setting_name')
|
|
|
- ->toArray();
|
|
|
+
|
|
|
+ //是否使用锁定库存校验 默认使用
|
|
|
+ $depart = array_shift($user['rule_depart']);
|
|
|
+ $is_stock = empty($depart['is_stock']) ? 1 : $depart['is_stock'];
|
|
|
|
|
|
foreach ($product_submit as $key => $value){
|
|
|
$tmp = explode(',',$key);
|
|
|
$product_id = $tmp[0];
|
|
|
- $pro_tmp = $pro[$product_id] ?? '';
|
|
|
- if(! $pro_tmp) return [false,'异常产品数据'];
|
|
|
- if(! isset($stock[$key])) return [false,'产品:'. $pro_tmp .'库存不存在'];
|
|
|
+ $pro_title = $pro[$product_id] ?? '';
|
|
|
+ if(! $pro_title) return [false,'异常产品数据'];
|
|
|
+ if(! isset($stock[$key])) return [false,'产品:'. $pro_title .'库存不存在'];
|
|
|
$stock_product = $stock[$key];
|
|
|
|
|
|
- if(! empty($setting_map['lock_number'])){//真实库存
|
|
|
+ if($is_stock == ProductInventorySet::type_one){
|
|
|
+ //校验锁定库存
|
|
|
$save_data = $product_save[$key] ?? 0;//已保存数量
|
|
|
$tmp_lock = ($stock_product['lock_number'] > 0 ? $stock_product['lock_number'] : 0) - $save_data;
|
|
|
$number = $stock_product['number'] - ($tmp_lock > 0 ? $tmp_lock : 0);
|
|
|
}else{
|
|
|
$number = $stock_product['number'];
|
|
|
}
|
|
|
- if($value > $number) return [false, $pro_tmp. '数量不足,当前数量:' . $number];
|
|
|
+ if($value > $number) return [false, $pro_title. '数量不足,当前数量:' . $number];
|
|
|
}
|
|
|
|
|
|
return [true,''];
|
|
@@ -333,4 +337,25 @@ class ProductInventoryService extends Service
|
|
|
|
|
|
return $array;
|
|
|
}
|
|
|
+
|
|
|
+ //库存设置列表
|
|
|
+ public function productInventorySetList($data, $user){
|
|
|
+ $model = new ProductInventorySet(['userData' => $user, 'search' => $data]);
|
|
|
+ $list = $model->where('del_time',0)
|
|
|
+ ->where('param_one','>',0)
|
|
|
+ ->select('id','top_depart_id','param_one')
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ //库存设置
|
|
|
+ public function productInventorySet($data, $user){
|
|
|
+ if(empty($data['id'])) return [false, 'ID不能为空'];
|
|
|
+
|
|
|
+ ProductInventorySet::where('id',$data['id'])
|
|
|
+ ->update(['param_one' => $data['param_one']]);
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
}
|