cqp 1 月之前
父節點
當前提交
f2d0320a18

+ 26 - 0
app/Http/Controllers/Api/ProductController.php

@@ -153,6 +153,32 @@ class ProductController extends BaseController
         }
     }
 
+    public function productUpdateByItemCode(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productUpdateByItemCode($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function productUpdateProductBasicInfo(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productUpdateProductBasicInfo($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function productGroupByListDetail(Request $request)
     {
         $service = new ProductService();

+ 13 - 0
app/Model/ProductItemCodeMessage.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class ProductItemCodeMessage extends Model
+{
+    protected $table = "product_item_code_message"; //指定表
+    const CREATED_AT = null;
+    const UPDATED_AT = null;
+    protected $dateFormat = 'U';
+}

+ 152 - 1
app/Service/ProductService.php

@@ -13,12 +13,14 @@ use App\Model\ProductCategory;
 use App\Model\ProductInfo;
 use App\Model\ProductIntroduction;
 use App\Model\ProductInventoryOfTop;
+use App\Model\ProductItemCodeMessage;
 use App\Model\ProductPriceDetail;
 use App\Model\Role;
 use App\Model\RoleMenuButton;
 use App\Model\SeeRange;
 use App\Model\Storehouse;
 use App\Model\U8Job;
+use Illuminate\Support\Arr;
 use Illuminate\Support\Facades\DB;
 
 /**
@@ -630,6 +632,13 @@ class ProductService extends Service
 
 //            $model->where('title', 'LIKE', '%'.$data['title'].'%');
         }
+        if(! empty($data['product_item_code_title'])){
+            $item_code = ProductItemCodeMessage::where('del_time',0)
+                ->where('title', 'LIKE', '%'.$data['product_item_code_title'].'%')
+                ->select('item_code')
+                ->get()->toArray();
+            $model->whereIn('item_code', array_column($item_code,'item_code'));
+        }
         if(isset($data['state'])) $model->where('state', $data['state']);
         if(isset($data['is_use'])) $model->where('is_use', $data['is_use']);
         if(isset($data['product_attribute'])) $model->where('product_attribute', $data['product_attribute']);
@@ -773,6 +782,8 @@ class ProductService extends Service
     public function productRule(&$data, $user, $is_add = true){
         if(empty($data['title'])) return [false,'产品名称不能为空'];
         if(empty($data['product_category_id'])) return [false,'产品分类不能为空'];
+        if(empty($data['product_category'])) return [false,'产品分类树结构不能为空'];
+        $data['product_category'] = json_encode($data['product_category']);
         if(empty($data['code'])) return [false,'产品编码不能为空'];
         if(! isset($data['cost'])) return [false, '请填写成本'];
         if(! isset($data['retail_price'])) return [false, '请填写零售价'];
@@ -792,7 +803,6 @@ class ProductService extends Service
                 }
             }
         }
-        if(! empty($data['product_category'])) $data['product_category'] = json_encode($data['product_category']);
 
         //所属部门 以及 顶级部门
         if(empty($data['depart_id'])) {
@@ -868,6 +878,11 @@ class ProductService extends Service
         $product_fs = [];
         if(! empty($search['fs_price_get'])) $product_fs = $this->getProductPriceDetail(['id' => $product_id], $user);
 
+        //商品编码关联信息
+        $item_code_map = ProductItemCodeMessage::where('del_time',0)
+            ->whereIn('item_code', array_column($data['data'],'item_code'))
+            ->pluck('title','item_code')
+            ->toArray();
         foreach ($data['data'] as $key => $value){
             $tmp = [];
             if(isset($detail_map[$value['id']])){
@@ -907,6 +922,7 @@ class ProductService extends Service
             $data['data'][$key]['stock'] = $stock_map[$value['id']] ?? (object)[];
             //成本
             $data['data'][$key]['cost_show'] = $value['cost'];
+            $data['data'][$key]['product_item_code_title'] = $item_code_map[$value['item_code']] ?? "";
         }
 
         return $data;
@@ -1277,10 +1293,17 @@ class ProductService extends Service
         //当前门店
         $top_depart = $user['depart_top'][0] ?? [];
 
+        //库存
         $stock = ProductInventoryOfTop::where('del_time',0)
             ->whereIn('product_id',$product_id)
             ->pluck('number','product_id')
             ->toArray();
+
+        //商品编码关联信息
+        $item_code_map = ProductItemCodeMessage::where('del_time',0)
+            ->whereIn('item_code', array_column($data['data'],'item_code'))
+            ->pluck('title','item_code')
+            ->toArray();
         foreach ($data['data'] as $key => $value){
             $arr = json_decode($value['product_category'], true);
             $arr = array_flip($arr);
@@ -1301,6 +1324,9 @@ class ProductService extends Service
             $data['data'][$key]['product_attribute_title'] = Product::$product_attribute[$value['product_attribute']] ?? "";
             $data['data'][$key]['stock'] = $this->returnStock($stock, $value);
             $data['data'][$key]['unit_title'] = $basic_map[$value['unit']] ?? "";
+            $title = $value['title'];
+            if(! empty($item_code_map[$value['item_code']])) $title = $item_code_map[$value['item_code']];
+            $data['data'][$key]['title'] = $title;
         }
 
         return $data;
@@ -1356,6 +1382,131 @@ class ProductService extends Service
         return [true, $product];
     }
 
+    public function productUpdateProductBasicInfo($data){
+        $time = time();
+        list($status, $msg) = $this->productUpdateProductBasicInfoRule($data,$time);
+        if(! $status) return [false, $msg];
+
+        //产品id 主表更新信息 子表插入信息 子表是否参与更新
+        list($product_id,$update,$insert_detail,$update_detail_bool) = $msg;
+//        dd($product_id,$update,$insert_detail,$update_detail_bool);
+
+        try {
+            DB::beginTransaction();
+
+            if(! empty($update)){
+                foreach ($product_id as $p_id){
+                    Product::where('id',$p_id)
+                        ->update($update);
+                }
+            }
+
+            if($update_detail_bool){
+                ProductPriceDetail::where('del_time',0)
+                    ->whereIn('product_id',$product_id)
+                    ->update(['del_time' => $time]);
+
+                if(! empty($insert_detail)) ProductPriceDetail::insert($insert_detail);
+            }
+
+            DB::commit();
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function productUpdateProductBasicInfoRule($data,$time){
+        if(empty($data['product_id'])) return [false, '产品ID不能为空'];
+        $product = Product::where('del_time',0)
+            ->whereIn('id',$data['product_id'])
+            ->select('id')
+            ->get()->toArray();
+        if(empty($product)) return [false, '产品不存在或已被删除'];
+        $product = array_column($product,'id');
+
+        // 产品分类   单位   成本   各分社价   商品编码   产品属性
+        $update = $update_detail = [];
+        if(! empty($data['product_category_id'])){
+            $update['product_category_id'] = $data['product_category_id'];
+            if(empty($data['product_category'])) return [false,'产品分类树结构不能为空'];
+            $product_category = json_encode($data['product_category']);
+            $update['product_category'] = $product_category;
+        }
+        if(Arr::has($data,'unit')) $update['unit'] = $data['unit'] ?? 0;
+        if(Arr::has($data,'cost')){
+            $cost = $data['cost'] ?? 0;
+            $res = $this->checkNumber($cost);
+            if(! $res) return [false,'成本请输入不超过两位小数并且大于等于0的数值'];
+            $update['cost'] = $cost;
+        }
+        if(Arr::has($data,'item_code')) $update['item_code'] = $data['item_code'] ?? "";
+        if(Arr::has($data,'product_attribute')) $update['product_attribute'] = $data['product_attribute'] ?? 0;
+        if(! empty($data['product_price'])){
+            $map = BasicType::whereIn('id',array_column($data['product_price'],'basic_type_id'))
+                ->pluck('title','id')
+                ->toArray();
+            foreach ($data['product_price'] as $value){
+                $price = $value['price'] ?? 0;
+                $tmp = $map[$value['basic_type_id']] ?? '';
+                if(! $tmp) return [false, '分社价格错误'];
+                $res = $this->checkNumber($price);
+                if(! $res) return [false, $tmp . '请输入不超过两位小数并且大于0的数值'];
+                $update_detail[] = [
+                    'product_id' => 0,
+                    'basic_type_id' => $value['basic_type_id'],
+                    'price' => $price,
+                    'crt_time' => $time,
+                ];
+            }
+        }
+        if(empty($update) && empty($update_detail)) return [false, '暂无更新'];
+        $update_detail_bool = false;
+
+        //详情信息
+        $insert_detail = [];
+        if(! empty($update_detail)){
+            $update_detail_bool = true;
+            foreach ($product as $p_id){
+                foreach ($update_detail as $detail){
+                    $detail['product_id'] = $p_id;
+                    $insert_detail[] = $detail;
+                }
+            }
+        }
+
+        return [true, [$product, $update, $insert_detail, $update_detail_bool]];
+    }
+
+    public function productUpdateByItemCode($data){
+        if(empty($data['item_code'])) return [false, "商品编码不能为空"];
+
+        $title = $data['title'] ?? '';
+        try {
+            DB::beginTransaction();
+
+            $time = time();
+
+            ProductItemCodeMessage::where('del_time',0)
+                ->where('item_code', $data['item_code'])
+                ->update(['del_time' => $time]);
+
+            ProductItemCodeMessage::insert([
+                'item_code' => $data['item_code'],
+                'title' => $title,
+            ]);
+
+            DB::commit();
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
     public function getProductByItemCode($item_code,$user){
         if(empty($item_code)) return [];
 

+ 40 - 27
app/Service/ScheduleService.php

@@ -653,34 +653,11 @@ class ScheduleService extends Service
 
             $button = [];
             if($value['state'] == Construction::STATE_TWO){
-                //分配/调配
-                if(in_array(RoleMenuButton::special_three,$special_button)){
-                    $button_tmp = $special_button_map[RoleMenuButton::special_three] ?? [];
-                    if(empty($emp_tmp)){
-                        $button_tmp['title'] = '分配';
-                        $button_tmp['type'] = 1;
-                    }else{
-                        $button_tmp['title'] = '调配';
-                        $button_tmp['type'] = 2;
-                    }
-                    $button[] = $button_tmp;
-                }
-
-                if(in_array(RoleMenuButton::special_four,$special_button)){
-                    //完结
-                    $button_tmp = $special_button_map[RoleMenuButton::special_four] ?? [];
-                    $button_tmp['is_button'] = 1;
-                    $button[] = $button_tmp;
-                }
+                //分配/调配  完结
+                $button = $this->fillFpButton($special_button,$special_button_map, $emp_tmp);
             }elseif($value['state'] == Construction::STATE_THREE){
-                //待确认
-                $button_tmp = $special_button_map[RoleMenuButton::special_five] ?? [];
-                if(in_array(RoleMenuButton::special_five,$special_button)){
-                    $button_tmp['is_button'] = 1;
-                }else{
-                    $button_tmp['is_button'] = 0;
-                }
-                $button[] = $button_tmp;
+                //待确认 分配/调配
+                $button = $this->fillFpButton($special_button,$special_button_map, $emp_tmp, 1);
             }
             $button = array_filter($button);
 
@@ -705,4 +682,40 @@ class ScheduleService extends Service
 
         return [true, $return];
     }
+
+    public function fillFpButton($special_button,$special_button_map,$emp_tmp, $type = 0){
+        $button = [];
+        //分配/调配
+        if(in_array(RoleMenuButton::special_three,$special_button)){
+            $button_tmp = $special_button_map[RoleMenuButton::special_three] ?? [];
+            if(empty($emp_tmp)){
+                $button_tmp['title'] = '分配';
+                $button_tmp['type'] = 1;
+            }else{
+                $button_tmp['title'] = '调配';
+                $button_tmp['type'] = 2;
+            }
+            $button[] = $button_tmp;
+        }
+
+        if(! $type){
+            //完结
+            if(in_array(RoleMenuButton::special_four,$special_button)){
+                $button_tmp = $special_button_map[RoleMenuButton::special_four] ?? [];
+                $button_tmp['is_button'] = 1;
+                $button[] = $button_tmp;
+            }
+        }else{
+            //待确认
+            $button_tmp = $special_button_map[RoleMenuButton::special_five] ?? [];
+            if(in_array(RoleMenuButton::special_five,$special_button)){
+                $button_tmp['is_button'] = 1;
+            }else{
+                $button_tmp['is_button'] = 0;
+            }
+            $button[] = $button_tmp;
+        }
+
+        return $button;
+    }
 }

+ 4 - 0
config/header/17.php

@@ -31,6 +31,10 @@ return [
         'value' => '商品编码',
     ],
     [
+        'key' => 'product_item_code_title',
+        'value' => '通用名称',
+    ],
+    [
         'key' => 'bar_code',
         'value' => '条码',
     ],

+ 2 - 0
routes/api.php

@@ -169,6 +169,8 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('batchUploadImg', 'Api\ProductController@batchUploadImg')->middleware('OssFileDeal');
     $route->any('batchBuildFee', 'Api\ProductController@batchBuildFee');
     $route->any('updateTopStock', 'Api\ProductController@updateTopStock');
+    $route->any('productUpdateByItemCode', 'Api\ProductController@productUpdateByItemCode');
+    $route->any('productUpdateProductBasicInfo', 'Api\ProductController@productUpdateProductBasicInfo');
 
     //采购单
     $route->any('purchaseOrderList', 'Api\PurchaseOrderController@purchaseOrderList');