|
@@ -9,6 +9,7 @@ use App\Model\Depart;
|
|
|
use App\Model\InOutRecord;
|
|
|
use App\Model\InvoiceOrder;
|
|
|
use App\Model\InvoiceOrderInfo;
|
|
|
+use App\Model\OrderOperation;
|
|
|
use App\Model\Product;
|
|
|
use App\Model\ProductCategory;
|
|
|
use App\Model\ProductInventory;
|
|
@@ -93,24 +94,28 @@ class ProductInventoryService extends Service
|
|
|
return $return;
|
|
|
}
|
|
|
|
|
|
+ //暂时关闭 没用
|
|
|
public static function is_check(&$user,$data){
|
|
|
+ return;
|
|
|
//是否校验库存
|
|
|
$top_depart_id = $user['head']['id'] ?? 0;//总公司id
|
|
|
- if($data['top_depart_id'] == $top_depart_id) $user['is_check_stock'] = false;
|
|
|
+ if($data['top_depart_id'] == $top_depart_id) {
|
|
|
+ $user['is_check_stock'] = false;
|
|
|
+ }else{
|
|
|
+ $set = ProductInventorySet::where('top_depart_id',$data['top_depart_id'])
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->first();
|
|
|
+ if(! empty($set) && ! $set->param_one) $user['is_check_stock'] = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//更新锁定库存
|
|
|
//$user 当前登录人的信息
|
|
|
//$submit_total (提交的数据) $save_total(保存过的数据)
|
|
|
public static function changeLockNumber($user, $submit_total = [], $save_total = []){
|
|
|
- if(empty($user['is_check_stock'])) return; //不校验库存
|
|
|
+ if($user['is_check_stock'] == ProductInventorySet::type_two) return; //不校验库存
|
|
|
if(empty($submit_total) && empty($save_total)) 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)){
|
|
|
foreach ($save_total as $key => $value){
|
|
@@ -133,45 +138,41 @@ class ProductInventoryService extends Service
|
|
|
|
|
|
//比较库存
|
|
|
public static function compareStock($user, $product_id = [],$product_submit = [], $product_save = []){
|
|
|
- if(empty($user['is_check_stock'])) return [true,'']; //不校验库存
|
|
|
+ if($user['is_check_stock'] == ProductInventorySet::type_two) return [true,'']; //不校验库存
|
|
|
if(empty($product_id) || empty($product_submit)) return [false,'比较参数不能为空'];
|
|
|
|
|
|
//库存
|
|
|
$array = ProductInventory::whereIn('product_id', $product_id)
|
|
|
->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'];
|
|
|
$stock[$key] = $value;
|
|
|
}
|
|
|
|
|
|
+ //产品字典
|
|
|
$pro = Product::whereIn('id',$product_id)
|
|
|
->pluck('title','id')
|
|
|
->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);
|
|
|
+ //产品ID
|
|
|
$product_id = $tmp[0];
|
|
|
+ //产品名称
|
|
|
$pro_title = $pro[$product_id] ?? '';
|
|
|
if(! $pro_title) return [false,'异常产品数据'];
|
|
|
- if(! isset($stock[$key])) return [false,'产品:'. $pro_title .'库存不存在'];
|
|
|
+ if(! isset($stock[$key])) return [false,'产品:'. $pro_title .'无库存记录'];
|
|
|
+ //产品库存
|
|
|
$stock_product = $stock[$key];
|
|
|
|
|
|
- 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_title. '数量不足,当前数量:' . $number];
|
|
|
+ //校验 =》 锁定库存
|
|
|
+ $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);
|
|
|
+ if($value > $number) return [false, $pro_title. '数量不足,当前有效库存数量:' . $number];
|
|
|
}
|
|
|
|
|
|
return [true,''];
|
|
@@ -370,25 +371,44 @@ class ProductInventoryService extends Service
|
|
|
//库存设置
|
|
|
public function productInventorySet($data, $user){
|
|
|
if(empty($data['id'])) return [false, 'ID不能为空'];
|
|
|
+ $set = ProductInventorySet::where('id',$data['id'])->first();
|
|
|
+ if(empty($set)) return [false,'系统设置不存在或已被删除'];
|
|
|
|
|
|
+ $msg = "";
|
|
|
if(isset($data['param_one'])){
|
|
|
- ProductInventorySet::where('id',$data['id'])
|
|
|
- ->update(['param_one' => $data['param_one']]);
|
|
|
+ if(! isset(ProductInventorySet::$type_name[$data['param_one']])) return [false,'系统设置参数错误'];
|
|
|
+ if($set->param_one != $data['param_one']) {
|
|
|
+ $set->param_one = $data['param_one'];
|
|
|
+ $msg .= "库存校验状态变更为:" . ProductInventorySet::$type_name[$data['param_one']];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(isset($data['param_two'])){
|
|
|
$res = $this->checkNumber($data['param_two']);
|
|
|
if(! $res) return [false, '整单扣除率请输入不超过两位小数并且大于0的数值'];
|
|
|
- ProductInventorySet::where('id',$data['id'])
|
|
|
- ->update(['param_two' => $data['param_two']]);
|
|
|
+ if($set->param_two != $data['param_two']) {
|
|
|
+ $set->param_two = $data['param_two'];
|
|
|
+ $msg .= ",整单扣除率变更为:" . $data['param_two'];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(isset($data['param_three'])){
|
|
|
$res = $this->checkNumber($data['param_three']);
|
|
|
- if(! $res) return [false, '比例请输入不超过两位小数并且大于0的数值'];
|
|
|
- if($data['param_three'] < 3) return [false,'比例不能小于3%'];
|
|
|
- ProductInventorySet::where('id',$data['id'])
|
|
|
- ->update(['param_three' => $data['param_three']]);
|
|
|
+ if(! $res) return [false, '施工费用比例请输入不超过两位小数并且大于0的数值'];
|
|
|
+ if($data['param_three'] < 3) return [false,'施工费用比例不能小于3%'];
|
|
|
+ if($set->param_three != $data['param_three']) {
|
|
|
+ $set->param_three = $data['param_three'];
|
|
|
+ $msg .= ",施工费用比例变更为:" . $data['param_three'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! empty($msg)){
|
|
|
+ $set->save();
|
|
|
+ (new OrderOperationService())->add([
|
|
|
+ 'order_number' => $data['id'],
|
|
|
+ 'msg' => OrderOperation::$type[OrderOperation::zero] . $msg,
|
|
|
+ 'type' => OrderOperation::zero
|
|
|
+ ],$user);
|
|
|
}
|
|
|
|
|
|
return [true, ''];
|