|
@@ -19,7 +19,7 @@ class ProductActivityService extends Service
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
$model = ProductActivity::where('id',$data['id'])->first();
|
|
|
- $model->title = $data['title'];
|
|
|
+ $model->title = $data['title'] ?? "";
|
|
|
$model->start_time = $data['start_time'] ?? 0;
|
|
|
$model->end_time = $data['end_time'] ?? 0;
|
|
|
$model->mark = $data['mark'] ?? '';
|
|
@@ -35,8 +35,8 @@ class ProductActivityService extends Service
|
|
|
$insert = [];
|
|
|
foreach ($data['product'] as $value){
|
|
|
$insert[] = [
|
|
|
- 'product_activity_id' => $model->id,
|
|
|
- 'product_id' => $model->id,
|
|
|
+ 'product_activity_id' => $data['id'],
|
|
|
+ 'product_id' => $value['product_id'],
|
|
|
'basic_type_id' => $value['basic_type_id'],
|
|
|
'price' => $value['price'],
|
|
|
'crt_time' => $time,
|
|
@@ -64,8 +64,7 @@ class ProductActivityService extends Service
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
$model = new ProductActivity();
|
|
|
- $model->product_category_id = $data['product_category_id'] ?? 0;
|
|
|
- $model->title = $data['title'];
|
|
|
+ $model->title = $data['title'] ?? "";
|
|
|
$model->start_time = $data['start_time'] ?? 0;
|
|
|
$model->end_time = $data['end_time'] ?? 0;
|
|
|
$model->mark = $data['mark'] ?? '';
|
|
@@ -81,7 +80,7 @@ class ProductActivityService extends Service
|
|
|
foreach ($data['product'] as $value){
|
|
|
$insert[] = [
|
|
|
'product_activity_id' => $model->id,
|
|
|
- 'product_id' => $model->id,
|
|
|
+ 'product_id' => $value['product_id'],
|
|
|
'basic_type_id' => $value['basic_type_id'],
|
|
|
'price' => $value['price'],
|
|
|
'crt_time' => $time,
|
|
@@ -138,14 +137,26 @@ class ProductActivityService extends Service
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
|
$customer['product'] = [];
|
|
|
+
|
|
|
+ //产品字典
|
|
|
+ $map = (new ProductService())->getProductDetail(array_unique(array_column($detail,'product_id')));
|
|
|
+
|
|
|
foreach ($detail as $value){
|
|
|
- $customer['product'][] = [
|
|
|
+ $basic_tmp = [
|
|
|
'basic_type_id' => $value['basic_type_id'],
|
|
|
'basic_type_title' => $title_map[$value['basic_type_id']] ?? '',
|
|
|
'price' => $value['price'],
|
|
|
];
|
|
|
+ if(! isset($customer['product'][$value['product_id']])){
|
|
|
+ $tmp = $map[$value['product_id']] ?? [];
|
|
|
+ $tmp['activity'][] = $basic_tmp;
|
|
|
+ $customer['product'][$value['product_id']] = $tmp;
|
|
|
+ }else{
|
|
|
+ $customer['product'][$value['product_id']]['activity'][] = $basic_tmp;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ $customer['product'] = array_values($customer['product']);
|
|
|
$customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
|
|
|
$customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
|
|
|
|
|
@@ -155,9 +166,20 @@ class ProductActivityService extends Service
|
|
|
public function productList($data,$user){
|
|
|
$model = new ProductActivity(['userData' => $user, 'search' => $data]);
|
|
|
$model = $model->where('del_time',0)
|
|
|
+ ->select('id','title','crt_id','mark','start_time','end_time','crt_time')
|
|
|
->orderby('id', 'desc');
|
|
|
|
|
|
if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
+ if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
|
+ $model->where('crt_time','>=',$return[0]);
|
|
|
+ $model->where('crt_time','<=',$return[1]);
|
|
|
+ }
|
|
|
+ if(! empty($data['activity_time'][0]) && ! empty($data['activity_time'][1])) {
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['activity_time']);
|
|
|
+ $model->where('start_time','>=',$return[0]);
|
|
|
+ $model->where('end_time','<=',$return[1]);
|
|
|
+ }
|
|
|
|
|
|
$list = $this->limit($model,'',$data);
|
|
|
$list = $this->fillData($list,$user);
|
|
@@ -172,17 +194,17 @@ class ProductActivityService extends Service
|
|
|
$data['end_time'] = $this->changeDateToDateMin($data['activity_time'][1]);
|
|
|
if($is_add){
|
|
|
$product = ProductActivityPrice::where('del_time',0)
|
|
|
- ->where('start', '<=', $data['end_time'])
|
|
|
- ->where('end', '>=', $data['start_time'])
|
|
|
+ ->where('start_time', '<=', $data['end_time'])
|
|
|
+ ->where('end_time', '>=', $data['start_time'])
|
|
|
->select('product_id')
|
|
|
->get()->toArray();
|
|
|
$product = array_column($product,'product_id');
|
|
|
}else{
|
|
|
if(empty($data['id'])) return [false,'ID不能为空'];
|
|
|
$product = ProductActivityPrice::where('del_time',0)
|
|
|
- ->where('id','<>',$data['id'])
|
|
|
- ->where('start', '<=', $data['end_time'])
|
|
|
- ->where('end', '>=', $data['start_time'])
|
|
|
+ ->where('product_activity_id','<>',$data['id'])
|
|
|
+ ->where('start_time', '<=', $data['end_time'])
|
|
|
+ ->where('end_time', '>=', $data['start_time'])
|
|
|
->select('product_id')
|
|
|
->get()->toArray();
|
|
|
$product = array_column($product,'product_id');
|
|
@@ -222,6 +244,9 @@ class ProductActivityService extends Service
|
|
|
->toArray();
|
|
|
|
|
|
foreach ($data['data'] as $key => $value){
|
|
|
+ $start_time = $value['start_time'] ? date("Y-m-d H:i",$value['start_time']) : '';
|
|
|
+ $end_time = $value['end_time'] ? date("Y-m-d H:i",$value['end_time']) : '';
|
|
|
+ $data['data'][$key]['activity_time'] = $start_time . '——' . $end_time;
|
|
|
$data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
$data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
|
|
|
}
|