|
@@ -8,6 +8,7 @@ use App\Model\Employee;
|
|
|
use App\Model\Product;
|
|
|
use App\Model\ProductCategory;
|
|
|
use App\Model\ProductInfo;
|
|
|
+use App\Model\ProductIntroduction;
|
|
|
use App\Model\ProductInventory;
|
|
|
use App\Model\ProductRange;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
@@ -138,11 +139,20 @@ class ProductService extends Service
|
|
|
$model->retail_price = $data['retail_price'] ?? 0;
|
|
|
$model->mark = $data['mark'] ?? '';
|
|
|
$model->state = $data['state'] ?? 0;
|
|
|
- $model->introduction = $data['introduction'] ?? '';
|
|
|
$model->save();
|
|
|
|
|
|
$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)
|
|
|
->where('product_id',$data['id'])
|
|
|
->update(['del_time' => $time]);
|
|
@@ -233,12 +243,18 @@ class ProductService extends Service
|
|
|
$model->retail_price = $data['retail_price'] ?? 0;
|
|
|
$model->mark = $data['mark'] ?? '';
|
|
|
$model->state = $data['state'] ?? 0;
|
|
|
- $model->introduction = $data['introduction'] ?? '';
|
|
|
$model->crt_id = $user['id'];
|
|
|
$model->save();
|
|
|
|
|
|
$time = time();
|
|
|
|
|
|
+ if(! empty($data['introduction'])){
|
|
|
+ $models = new ProductIntroduction();
|
|
|
+ $models->product_id = $model->id;
|
|
|
+ $models->introduction = $data['introduction'];
|
|
|
+ $models->save();
|
|
|
+ }
|
|
|
+
|
|
|
if(! empty($data['img'])){
|
|
|
$insert = [];
|
|
|
foreach ($data['img'] as $value){
|
|
@@ -311,6 +327,10 @@ class ProductService extends Service
|
|
|
|
|
|
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)
|
|
|
->where('product_id',$data['id'])
|
|
|
->update(['del_time' => $time]);
|
|
@@ -336,12 +356,21 @@ class ProductService extends Service
|
|
|
->first();
|
|
|
if(empty($customer)) return [false,'产品不存在或已被删除'];
|
|
|
$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');
|
|
|
$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);
|
|
|
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')))
|
|
|
->pluck('title','id')
|
|
|
->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')
|
|
|
->toArray();
|
|
|
|
|
@@ -466,7 +495,7 @@ class ProductService extends Service
|
|
|
$data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
|
|
|
$data['data'][$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
|
|
|
$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;
|