|
@@ -15,6 +15,8 @@ use App\Model\Inventory;
|
|
|
use App\Model\InventorySub;
|
|
|
use App\Model\LastJc;
|
|
|
use App\Model\Product;
|
|
|
+use App\Model\ProductAdjustment;
|
|
|
+use App\Model\ProductAdjustmentSub;
|
|
|
use App\Model\ProductCategory;
|
|
|
use App\Model\ProductInventorySet;
|
|
|
use App\Model\ProductPriceDetail;
|
|
@@ -38,6 +40,7 @@ class ImportService extends Service
|
|
|
'btOnline', //补贴订单
|
|
|
'lastJc', //上月结存
|
|
|
'inventory', // 盘点
|
|
|
+ 'productAdjustment', // 产品金额调整单
|
|
|
];
|
|
|
|
|
|
//写活的导入------------------- 暂时不好用
|
|
@@ -235,6 +238,17 @@ class ImportService extends Service
|
|
|
return [true, $config_array,$filename];
|
|
|
}
|
|
|
|
|
|
+ private function productAdjustment($data,$user){
|
|
|
+ //生成下载文件
|
|
|
+ $filename = "产品金额调整单导入模板_" . time() . '.' . 'xlsx';
|
|
|
+
|
|
|
+ //获取配置文件
|
|
|
+ $config = "excel.productAdjustment";
|
|
|
+ $config_array = config($config) ?? [];
|
|
|
+ if(empty($config_array)) return [false, '配置文件不存在',''];
|
|
|
+ return [true, $config_array,$filename];
|
|
|
+ }
|
|
|
+
|
|
|
//导入入口
|
|
|
public function importAll($data,$user){
|
|
|
// //不超时
|
|
@@ -1706,5 +1720,126 @@ class ImportService extends Service
|
|
|
|
|
|
return [true, ''];
|
|
|
}
|
|
|
+
|
|
|
+ public function productAdjustmentImport($array, $user){
|
|
|
+ $head = $user['head']['id'] ?? 0;
|
|
|
+
|
|
|
+ // 去除表头
|
|
|
+ unset($array[0]);
|
|
|
+ if(empty($array)) return [false, '导入数据不能为空'];
|
|
|
+
|
|
|
+ $shop_name = $product_code = [];
|
|
|
+ foreach ($array as $key => $value){
|
|
|
+ $rowData = array_filter($value);
|
|
|
+ if (empty($rowData)) {
|
|
|
+ unset($array[$key]);
|
|
|
+ } elseif(empty($value[0]) || empty($value[1]) || empty($value[2])) {
|
|
|
+ if($key != 1){
|
|
|
+ if(empty($value[1])) return [false, '带*号的字段项必填'];
|
|
|
+ } else{
|
|
|
+ return [false, '带*号的字段项必填'];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ foreach ($value as $k => $v){
|
|
|
+ $value[$k] = trim($v);
|
|
|
+ }
|
|
|
+ if($value[0] && ! in_array($value[0],$shop_name)) $shop_name[] = $value[0];
|
|
|
+ if(! in_array($value[1],$product_code)) {
|
|
|
+ $product_code[] = $value[1];
|
|
|
+ }else{
|
|
|
+ return [false, '产品编号:' . $value[1] .'已存在'];
|
|
|
+ }
|
|
|
+ if(! is_numeric($value[2])) return [false, '调整金额请填写正确的数值'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(count($shop_name) != 1) return [false, '只允许单门店创建调整金额'];
|
|
|
+
|
|
|
+ //门店信息
|
|
|
+ $depart = Depart::whereIn('title',$shop_name)
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->where('parent_id',0)
|
|
|
+ ->select('id','title')
|
|
|
+ ->first();
|
|
|
+ if(empty($depart)) return [false, "门店:" .$shop_name . "不存在或已被删除"];
|
|
|
+ $depart = $depart->toArray();
|
|
|
+ $top_depart_id = $depart['id'];
|
|
|
+
|
|
|
+ //门店的仓库
|
|
|
+ $storehouse = Storehouse::where('top_depart_id', $top_depart_id)
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->select('id')
|
|
|
+ ->first();
|
|
|
+ if(empty($storehouse)) return [false, "门店:" .$shop_name . "的仓库不存在或已被删除"];
|
|
|
+ $storehouse = $storehouse->toArray();
|
|
|
+ $storehouse_id = $storehouse['id'];
|
|
|
+ if(empty($storehouse_id)) return [false, "门店:" .$shop_name . "的仓库不存在或已被删除"];
|
|
|
+
|
|
|
+ //产品
|
|
|
+ $model = Product::ProductClear($user,[]);
|
|
|
+ $product = $model->whereIn('code',$product_code)
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->select('id','code')
|
|
|
+ ->get()->toArray();
|
|
|
+ $product_map = array_column($product,'id','code');
|
|
|
+
|
|
|
+ $product_submit = [];
|
|
|
+ foreach ($product as $value){
|
|
|
+ $key = $value['id'] . ',' . $storehouse_id;
|
|
|
+ if(! isset($product_submit[$key])) $product_submit[$key] = 0;
|
|
|
+ }
|
|
|
+ //校验是否存在产品调整
|
|
|
+ list($status, $msg) = (new ProductAdjustService())->issetProduct(['top_depart_id' => $top_depart_id], $product_submit);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+ $sub = [];
|
|
|
+ foreach ($array as $value){
|
|
|
+ $product_tmp = $product_map[$value[1]] ?? 0;
|
|
|
+ if($product_tmp <= 0) return [false, "产品编码:" . $value[1] . "不存在或已被删除"];
|
|
|
+
|
|
|
+ $sub[] = [
|
|
|
+ 'product_id' => $product_tmp,
|
|
|
+ 'storehouse_id' => $storehouse_id,
|
|
|
+ 'order_number' => "",
|
|
|
+ 'product_adjustment_id' => 0,
|
|
|
+ 'final_amount' => $value[2],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if(empty($sub)) return [false, '暂无需要写入的产品调整单数据'];
|
|
|
+
|
|
|
+ try{
|
|
|
+ $order_number = (new OrderNoService())->createOrderNumber(ProductAdjustment::prefix);
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $inventory_model = new ProductAdjustment();
|
|
|
+ $inventory_model->order_number = $order_number;
|
|
|
+ $inventory_model->storehouse_id = $storehouse_id;
|
|
|
+ $inventory_model->counted_id = $user['id'];
|
|
|
+ $inventory_model->counted_time = $time;
|
|
|
+ $inventory_model->depart_id = $top_depart_id;
|
|
|
+ $inventory_model->top_depart_id = $top_depart_id;
|
|
|
+ $inventory_model->crt_id = $user['id'];
|
|
|
+ $inventory_model->save();
|
|
|
+
|
|
|
+ foreach ($sub as $key => $value){
|
|
|
+ $sub[$key]['product_adjustment_id'] = $inventory_model->id;
|
|
|
+ $sub[$key]['order_number'] = $order_number;
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入数据
|
|
|
+ ProductAdjustmentSub::insert($sub);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ if (str_contains($exception->getMessage(), '1062') || str_contains($exception->getMessage(), 'Duplicate entry')) {
|
|
|
+ return [false, '网络波动,请重新操作!'];
|
|
|
+ }
|
|
|
+ return [false, $exception->getMessage() . $exception->getLine() . $exception->getCode()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
}
|
|
|
|