|
@@ -5,6 +5,7 @@ namespace App\Service;
|
|
|
use App\Model\BasicType;
|
|
|
use App\Model\Employee;
|
|
|
use App\Model\Product;
|
|
|
+use App\Model\ProductActivity;
|
|
|
use App\Model\ProductActivityPrice;
|
|
|
use App\Model\ProductCategory;
|
|
|
use App\Model\ProductInfo;
|
|
@@ -181,6 +182,7 @@ class ProductService extends Service
|
|
|
|
|
|
$model = Product::where('id',$data['id'])->first();
|
|
|
$model->product_category_id = $data['product_category_id'] ?? 0;
|
|
|
+ $model->product_category = $data['product_category'] ?? '';
|
|
|
$model->title = $data['title'];
|
|
|
$model->code = $data['code'] ?? '';
|
|
|
$model->sn_code = $data['sn_code'] ?? '';
|
|
@@ -278,6 +280,7 @@ class ProductService extends Service
|
|
|
|
|
|
$model = new Product();
|
|
|
$model->product_category_id = $data['product_category_id'] ?? 0;
|
|
|
+ $model->product_category = $data['product_category'] ?? '';
|
|
|
$model->title = $data['title'];
|
|
|
$model->code = $data['code'] ?? '';
|
|
|
$model->sn_code = $data['sn_code'] ?? '';
|
|
@@ -402,6 +405,7 @@ class ProductService extends Service
|
|
|
->first();
|
|
|
if(empty($customer)) return [false,'产品不存在或已被删除'];
|
|
|
$customer = $customer->toArray();
|
|
|
+ $customer['product_category'] = ! empty($customer['product_category']) ? json_decode($customer['product_category'],true): [];
|
|
|
$category = ProductCategory::where('id',$customer['product_category_id'])
|
|
|
->value('title');
|
|
|
$customer['product_category_title'] = $category;
|
|
@@ -491,6 +495,34 @@ class ProductService extends Service
|
|
|
return [true, $list];
|
|
|
}
|
|
|
|
|
|
+ public function productList2($data,$user){
|
|
|
+ $model = ProductCategory::TopClear($user,$data);
|
|
|
+ $model = $model->where('del_time',0)
|
|
|
+ ->select('title','id','parent_id')
|
|
|
+ ->orderby('id','desc');
|
|
|
+ if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
+
|
|
|
+ $list = $model->get()->toArray();
|
|
|
+ if(! empty($list)) {
|
|
|
+ $productList = Product::where('del_time',0)
|
|
|
+ ->whereIn('product_category_id',array_column($list,'id'))
|
|
|
+ ->select('id','product_category_id','title','code','sn_code')
|
|
|
+ ->get()->toArray();
|
|
|
+ $productMap = [];
|
|
|
+ foreach ($productList as $value){
|
|
|
+ $productMap[$value['product_category_id']][] = $value;
|
|
|
+ }
|
|
|
+ foreach ($list as $key => $value){
|
|
|
+ if(isset($productMap[$value['id']])) $list[$key]['product'] = $productMap[$value['id']];
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = $this->makeTree(0,$list);
|
|
|
+ $list = $this->set_sort_circle($list);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [200, $list];
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 产品参数规则
|
|
|
* @param $data
|
|
@@ -520,6 +552,7 @@ class ProductService extends Service
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if(! empty($data['product_category'])) $data['product_category'] = json_encode($data['product_category']);
|
|
|
|
|
|
//所属部门 以及 顶级部门
|
|
|
if(empty($data['depart_id'])) {
|
|
@@ -616,26 +649,44 @@ class ProductService extends Service
|
|
|
|
|
|
//获取产品使用价格
|
|
|
public function getProductPrice($product_id = [], $type = 1){
|
|
|
- //type 1 采购 2 合同
|
|
|
+ //type 1 采购 2 合同 和 活动包
|
|
|
|
|
|
$detail_map = [];
|
|
|
+ $time = time();
|
|
|
if($type == 1) {
|
|
|
- //分社价
|
|
|
+ //供应商活动价格
|
|
|
+ $activity = ProductActivityPrice::from('product_activity_price as a')
|
|
|
+ ->join('product_activity as b','b.id','a.product_activity_id')
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->whereIn('a.product_id',$product_id)
|
|
|
+ ->where('a.start_time','<=',$time)
|
|
|
+ ->where('a.end_time','>=',$time)
|
|
|
+ ->where('b.type',ProductActivity::type_two)
|
|
|
+ ->select('a.product_id','a.basic_type_id','a.price')
|
|
|
+ ->get()->toArray();
|
|
|
+ foreach ($activity as $value){
|
|
|
+ $detail_map[$value['product_id']][] = $value;
|
|
|
+ }
|
|
|
+ //分社价 没有供应商活动价格使用分社价格
|
|
|
$detail = ProductPriceDetail::where('del_time',0)
|
|
|
->whereIn('product_id',$product_id)
|
|
|
->select('product_id','basic_type_id','price')
|
|
|
->get()->toArray();
|
|
|
foreach ($detail as $value){
|
|
|
- $detail_map[$value['product_id']][] = $value;
|
|
|
+ if(! isset($detail_map[$value['product_id']])){
|
|
|
+ $detail_map[$value['product_id']][] = $value;
|
|
|
+ }
|
|
|
}
|
|
|
}else{
|
|
|
- //活动价格
|
|
|
- $time = time();
|
|
|
- $activity = ProductActivityPrice::where('del_time',0)
|
|
|
- ->whereIn('product_id',$product_id)
|
|
|
- ->where('start_time','<=',$time)
|
|
|
- ->where('end_time','>=',$time)
|
|
|
- ->select('product_id','basic_type_id','price')
|
|
|
+ //零售活动价格
|
|
|
+ $activity = ProductActivityPrice::from('product_activity_price as a')
|
|
|
+ ->join('product_activity as b','b.id','a.product_activity_id')
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->whereIn('a.product_id',$product_id)
|
|
|
+ ->where('a.start_time','<=',$time)
|
|
|
+ ->where('a.end_time','>=',$time)
|
|
|
+ ->where('b.type',ProductActivity::type_one)
|
|
|
+ ->select('a.product_id','a.basic_type_id','a.price')
|
|
|
->get()->toArray();
|
|
|
foreach ($activity as $value){
|
|
|
$detail_map[$value['product_id']][] = $value;
|