cqpCow 1 年之前
父節點
當前提交
048e1e0975
共有 3 個文件被更改,包括 49 次插入7 次删除
  1. 1 1
      app/Http/Controllers/Api/ProductController.php
  2. 13 0
      app/Model/ProductIntroduction.php
  3. 35 6
      app/Service/ProductService.php

+ 1 - 1
app/Http/Controllers/Api/ProductController.php

@@ -105,7 +105,7 @@ class ProductController extends BaseController
     {
     {
         $service = new ProductService();
         $service = new ProductService();
         $user = $request->userData->toArray();
         $user = $request->userData->toArray();
-        list($status,$data) = $service->productList($request->all());
+        list($status,$data) = $service->productList($request->all(),$user);
 
 
         if($status){
         if($status){
             return $this->json_return(200,'',$data);
             return $this->json_return(200,'',$data);

+ 13 - 0
app/Model/ProductIntroduction.php

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

+ 35 - 6
app/Service/ProductService.php

@@ -8,6 +8,7 @@ use App\Model\Employee;
 use App\Model\Product;
 use App\Model\Product;
 use App\Model\ProductCategory;
 use App\Model\ProductCategory;
 use App\Model\ProductInfo;
 use App\Model\ProductInfo;
+use App\Model\ProductIntroduction;
 use App\Model\ProductInventory;
 use App\Model\ProductInventory;
 use App\Model\ProductRange;
 use App\Model\ProductRange;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\DB;
@@ -138,11 +139,20 @@ class ProductService extends Service
             $model->retail_price = $data['retail_price'] ?? 0;
             $model->retail_price = $data['retail_price'] ?? 0;
             $model->mark = $data['mark'] ?? '';
             $model->mark = $data['mark'] ?? '';
             $model->state = $data['state'] ?? 0;
             $model->state = $data['state'] ?? 0;
-            $model->introduction = $data['introduction'] ?? '';
             $model->save();
             $model->save();
 
 
             $time = time();
             $time = time();
 
 
+            ProductIntroduction::where('product_id',$data['id'])
+                ->where('del_time',0)
+                ->update(['del_time' => $time]);
+            if(! empty($data['introduction'])){
+                $models = new ProductIntroduction();
+                $models->product_id = $model->id;
+                $models->introduction = $data['introduction'];
+                $models->save();
+            }
+
             ProductInfo::where('del_time',0)
             ProductInfo::where('del_time',0)
                 ->where('product_id',$data['id'])
                 ->where('product_id',$data['id'])
                 ->update(['del_time' => $time]);
                 ->update(['del_time' => $time]);
@@ -233,12 +243,18 @@ class ProductService extends Service
             $model->retail_price = $data['retail_price'] ?? 0;
             $model->retail_price = $data['retail_price'] ?? 0;
             $model->mark = $data['mark'] ?? '';
             $model->mark = $data['mark'] ?? '';
             $model->state = $data['state'] ?? 0;
             $model->state = $data['state'] ?? 0;
-            $model->introduction = $data['introduction'] ?? '';
             $model->crt_id = $user['id'];
             $model->crt_id = $user['id'];
             $model->save();
             $model->save();
 
 
             $time = time();
             $time = time();
 
 
+            if(! empty($data['introduction'])){
+                $models = new ProductIntroduction();
+                $models->product_id = $model->id;
+                $models->introduction = $data['introduction'];
+                $models->save();
+            }
+
             if(! empty($data['img'])){
             if(! empty($data['img'])){
                 $insert = [];
                 $insert = [];
                 foreach ($data['img'] as $value){
                 foreach ($data['img'] as $value){
@@ -311,6 +327,10 @@ class ProductService extends Service
 
 
             Product::where('id',$data['id'])->update(['del_time' => $time]);
             Product::where('id',$data['id'])->update(['del_time' => $time]);
 
 
+            ProductIntroduction::where('product_id',$data['id'])
+                ->where('del_time',0)
+                ->update(['del_time' => $time]);
+
             ProductInfo::where('del_time',0)
             ProductInfo::where('del_time',0)
                 ->where('product_id',$data['id'])
                 ->where('product_id',$data['id'])
                 ->update(['del_time' => $time]);
                 ->update(['del_time' => $time]);
@@ -336,12 +356,21 @@ class ProductService extends Service
             ->first();
             ->first();
         if(empty($customer)) return [false,'产品不存在或已被删除'];
         if(empty($customer)) return [false,'产品不存在或已被删除'];
         $customer = $customer->toArray();
         $customer = $customer->toArray();
+        $category = ProductCategory::where('id',$customer['product_category_id'])
+            ->value('title');
+        $customer['product_category_title'] = $category;
+        $customer['introduction'] = "";
+        $in = ProductIntroduction::where('del_time',0)
+            ->where('product_id',$data['id'])
+            ->first();
+        if($in) $customer['introduction'] = $in->introduction;
+
         //单位
         //单位
         $title = BasicType::where('id',$customer['unit'])->value('title');
         $title = BasicType::where('id',$customer['unit'])->value('title');
         $customer['unit_name'] = $title;
         $customer['unit_name'] = $title;
         //库存
         //库存
-        $customer['product_inventory'] = [];
-        $depart_id = array_column($user['rule_depart'],'depart_id');
+        $customer['product_inventory'] = $depart_id = [];
+        if(! $user['is_main']) $depart_id = array_column($user['rule_depart'],'depart_id');
         $inventory = $this->getProductInventory([$data['id']], $depart_id);
         $inventory = $this->getProductInventory([$data['id']], $depart_id);
         if(! empty($inventory)) $customer['product_inventory'] = $inventory;
         if(! empty($inventory)) $customer['product_inventory'] = $inventory;
 
 
@@ -457,7 +486,7 @@ class ProductService extends Service
         $category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
         $category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
             ->pluck('title','id')
             ->pluck('title','id')
             ->toArray();
             ->toArray();
-        $basic = BasicType::where('id',array_unique(array_column($data['data'],'unit')))
+        $basic_map = BasicType::whereIn('id',array_unique(array_column($data['data'],'unit')))
             ->pluck('title','id')
             ->pluck('title','id')
             ->toArray();
             ->toArray();
 
 
@@ -466,7 +495,7 @@ class ProductService extends Service
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
             $data['data'][$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
             $data['data'][$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
             $data['data'][$key]['state_name'] = Product::$state[$value['state']] ?? '';
             $data['data'][$key]['state_name'] = Product::$state[$value['state']] ?? '';
-            $data['data'][$key]['unit_name'] = $basic[$value['unit']] ?? '';
+            $data['data'][$key]['unit_name'] = $basic_map[$value['unit']] ?? '';
         }
         }
 
 
         return $data;
         return $data;