|
@@ -88,40 +88,82 @@ class Product extends Controller
|
|
|
$is_admin = request('access_token.is_admin', '0');
|
|
$is_admin = request('access_token.is_admin', '0');
|
|
|
// 查询条件
|
|
// 查询条件
|
|
|
$map = [];
|
|
$map = [];
|
|
|
|
|
+ $map2 = [];
|
|
|
|
|
+ $map3 = [];
|
|
|
$start_time = request('start_time', '');
|
|
$start_time = request('start_time', '');
|
|
|
$end_time = request('end_time', '');
|
|
$end_time = request('end_time', '');
|
|
|
$product_name = request('product_name', '');
|
|
$product_name = request('product_name', '');
|
|
|
$product_brand = request('product_brand', '');
|
|
$product_brand = request('product_brand', '');
|
|
|
$platform = request('platform', '');
|
|
$platform = request('platform', '');
|
|
|
// 时间条件
|
|
// 时间条件
|
|
|
- if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
|
|
|
|
|
- if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
|
|
|
|
|
|
|
+ if ($start_time){
|
|
|
|
|
+ $map[] = ['insert_time', '>=', strtotime($start_time)];
|
|
|
|
|
+ $map2[] = ['insert_time', '>=', strtotime($start_time)];
|
|
|
|
|
+ $map3[] = ['insert_time', '>=', strtotime($start_time)];
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($end_time){
|
|
|
|
|
+ $map[] = ['insert_time', '<=', strtotime($end_time)];
|
|
|
|
|
+ $map2[] = ['insert_time', '<=', strtotime($end_time)];
|
|
|
|
|
+ $map3[] = ['insert_time', '<=', strtotime($end_time)];
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
// 其他条件
|
|
// 其他条件
|
|
|
$map[] = ['status', '=', 0];
|
|
$map[] = ['status', '=', 0];
|
|
|
- if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
|
|
|
|
|
- if (is_numeric($platform) || $platform) $map[] = ['platform', 'like', "%$platform%"];
|
|
|
|
|
|
|
+ if ($product_name) $map2[] = ['product_name', 'like', "%$product_name%"];
|
|
|
|
|
+ if (is_numeric($platform) || $platform){
|
|
|
|
|
+ $map[] = ['platform', 'like', "%$platform%"];
|
|
|
|
|
+ $map2[] = ['platform', 'like', "%$platform%"];
|
|
|
|
|
+ $map3[] = ['platform', 'like', "%$platform%"];
|
|
|
|
|
+ }
|
|
|
if ($product_brand) $map[] = ['product_brand', 'like', "%$product_brand%"];
|
|
if ($product_brand) $map[] = ['product_brand', 'like', "%$product_brand%"];
|
|
|
// 权限判断
|
|
// 权限判断
|
|
|
if ($is_admin != 1 && $company_id != 0) {
|
|
if ($is_admin != 1 && $company_id != 0) {
|
|
|
$map[] = ['company_id', '=', $company_id];
|
|
$map[] = ['company_id', '=', $company_id];
|
|
|
|
|
+ $map2[] = ['company_id', '=', $company_id];
|
|
|
|
|
+ $map3[] = ['company_id', '=', $company_id];
|
|
|
} else {
|
|
} else {
|
|
|
$map[] = ['company_id', '=', $admin_company_id];
|
|
$map[] = ['company_id', '=', $admin_company_id];
|
|
|
|
|
+ $map2[] = ['company_id', '=', $admin_company_id];
|
|
|
|
|
+ $map3[] = ['company_id', '=', $admin_company_id];
|
|
|
}
|
|
}
|
|
|
// 查询数据
|
|
// 查询数据
|
|
|
$result = $ProductModel->query()
|
|
$result = $ProductModel->query()
|
|
|
->where($map)
|
|
->where($map)
|
|
|
- ->with(['product_keyword'])
|
|
|
|
|
- ->select(['id','product_brand','product_name', 'product_specs'])
|
|
|
|
|
- ->distinct('product_name')
|
|
|
|
|
|
|
+ ->where([['product_brand', '!=', ''], ['product_brand', '!=', null]])
|
|
|
|
|
+ ->select([DB::raw('MAX(id) as id'),'product_brand'])
|
|
|
|
|
+ ->groupBy(['product_brand'])
|
|
|
->orderByDesc('id')->get()->toarray();
|
|
->orderByDesc('id')->get()->toarray();
|
|
|
- // 分配数据
|
|
|
|
|
if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
|
|
if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
|
|
|
- if (count($result) > 0) {
|
|
|
|
|
- foreach ($result as $key => $value) {
|
|
|
|
|
- $product_specs = isset($value['product_specs']) ? explode(',', $value['product_specs']) : '';
|
|
|
|
|
- //移除空数组
|
|
|
|
|
- $result[$key]['product_specs'] = $product_specs ? array_filter($product_specs) : '';
|
|
|
|
|
|
|
+ foreach ($result as $key => $value) {
|
|
|
|
|
+ $product_list = $ProductModel->query()
|
|
|
|
|
+ ->where($map2)
|
|
|
|
|
+ ->where([['product_name', '!=', ''], ['product_name', '!=', null]])
|
|
|
|
|
+ ->with(['product_keyword'])
|
|
|
|
|
+ ->where(['product_brand' => $value['product_brand']])
|
|
|
|
|
+ ->select([DB::raw('MAX(id) as id'), 'product_name'])
|
|
|
|
|
+ ->groupBy(['product_name'])
|
|
|
|
|
+ ->orderByDesc('id')->get()->toarray();
|
|
|
|
|
+ if (!empty($product_list)) {
|
|
|
|
|
+ foreach ($product_list as $key2 => $value2) {
|
|
|
|
|
+ $product_specs = $ProductModel->query()
|
|
|
|
|
+ ->where($map3)
|
|
|
|
|
+ ->where([['product_specs', '!=', ''], ['product_specs', '!=', null]])
|
|
|
|
|
+ ->where(['product_name' => $value2['product_name']])
|
|
|
|
|
+ ->select([DB::raw('MAX(id) as id'), 'product_specs'])
|
|
|
|
|
+ ->groupBy(['product_specs'])
|
|
|
|
|
+ ->orderByDesc('id')->get()->toarray();
|
|
|
|
|
+ if (count($product_specs) > 0) {
|
|
|
|
|
+ foreach ($product_specs as $key3 => $value3) {
|
|
|
|
|
+ $product_specs_item = isset($value3['product_specs']) ? explode(',', $value3['product_specs']) : '';
|
|
|
|
|
+ //移除空数组
|
|
|
|
|
+ $product_specs[$key3]['product_specs'] = $product_specs_item ? array_filter($product_specs_item) : '';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //移除空数组
|
|
|
|
|
+ $product_list[$key2]['product_specs'] = $product_specs ? array_filter($product_specs) : '';
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ $result[$key]['product_list'] = !empty($product_list) ? $product_list : [];
|
|
|
}
|
|
}
|
|
|
// 加载模板
|
|
// 加载模板
|
|
|
return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
|
|
return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
|
|
@@ -185,7 +227,7 @@ class Product extends Controller
|
|
|
$product_keyword = request('product_keyword', '');
|
|
$product_keyword = request('product_keyword', '');
|
|
|
$all_data['product_brand'] = $product_brand;
|
|
$all_data['product_brand'] = $product_brand;
|
|
|
$all_data['product_keyword'] = $product_keyword;
|
|
$all_data['product_keyword'] = $product_keyword;
|
|
|
- if(trim($product_keyword) !=''){
|
|
|
|
|
|
|
+ if (trim($product_keyword) != '') {
|
|
|
$product_keyword_count = count(explode(',', $product_keyword));
|
|
$product_keyword_count = count(explode(',', $product_keyword));
|
|
|
if ($product_keyword_count > 5) {
|
|
if ($product_keyword_count > 5) {
|
|
|
return json_send(['code' => 'error', 'msg' => '商品关键词不能超过5个']);
|
|
return json_send(['code' => 'error', 'msg' => '商品关键词不能超过5个']);
|
|
@@ -205,7 +247,7 @@ class Product extends Controller
|
|
|
$all_data['sampling_start_time'] = $sampling_start_time ? strtotime($sampling_start_time . '00:00:00') : '0';
|
|
$all_data['sampling_start_time'] = $sampling_start_time ? strtotime($sampling_start_time . '00:00:00') : '0';
|
|
|
$all_data['sampling_end_time'] = $sampling_end_time ? strtotime($sampling_end_time . '23:59:59') : '0';
|
|
$all_data['sampling_end_time'] = $sampling_end_time ? strtotime($sampling_end_time . '23:59:59') : '0';
|
|
|
$all_data['minimum_order_quantity'] = $minimum_order_quantity;
|
|
$all_data['minimum_order_quantity'] = $minimum_order_quantity;
|
|
|
- if ($all_data['sampling_start_time'] && strtotime(date('Y-m-d', $all_data['sampling_start_time']). '23:59:59') < time()) return json_send(['code' => 'error', 'msg' => '采集开始时间必须大于当前时间']);
|
|
|
|
|
|
|
+ if ($all_data['sampling_start_time'] && strtotime(date('Y-m-d', $all_data['sampling_start_time']) . '23:59:59') < time()) return json_send(['code' => 'error', 'msg' => '采集开始时间必须大于当前时间']);
|
|
|
if ($all_data['sampling_end_time'] && $all_data['sampling_end_time'] < time()) return json_send(['code' => 'error', 'msg' => '采集结束时间必须大于当前时间']);
|
|
if ($all_data['sampling_end_time'] && $all_data['sampling_end_time'] < time()) return json_send(['code' => 'error', 'msg' => '采集结束时间必须大于当前时间']);
|
|
|
//查询是否存在
|
|
//查询是否存在
|
|
|
$map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
|
|
$map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
|
|
@@ -252,7 +294,7 @@ class Product extends Controller
|
|
|
$product_keyword = request('product_keyword', '');
|
|
$product_keyword = request('product_keyword', '');
|
|
|
$all_data['product_brand'] = $product_brand;
|
|
$all_data['product_brand'] = $product_brand;
|
|
|
$all_data['product_keyword'] = $product_keyword;
|
|
$all_data['product_keyword'] = $product_keyword;
|
|
|
- if(trim($product_keyword) !=''){
|
|
|
|
|
|
|
+ if (trim($product_keyword) != '') {
|
|
|
$product_keyword_count = count(explode(',', $product_keyword));
|
|
$product_keyword_count = count(explode(',', $product_keyword));
|
|
|
if ($product_keyword_count > 5) {
|
|
if ($product_keyword_count > 5) {
|
|
|
return json_send(['code' => 'error', 'msg' => '商品关键词不能超过5个']);
|
|
return json_send(['code' => 'error', 'msg' => '商品关键词不能超过5个']);
|
|
@@ -272,7 +314,7 @@ class Product extends Controller
|
|
|
$all_data['sampling_start_time'] = $sampling_start_time ? strtotime($sampling_start_time . '00:00:00') : '0';
|
|
$all_data['sampling_start_time'] = $sampling_start_time ? strtotime($sampling_start_time . '00:00:00') : '0';
|
|
|
$all_data['sampling_end_time'] = $sampling_end_time ? strtotime($sampling_end_time . '23:59:59') : '0';
|
|
$all_data['sampling_end_time'] = $sampling_end_time ? strtotime($sampling_end_time . '23:59:59') : '0';
|
|
|
$all_data['minimum_order_quantity'] = $minimum_order_quantity;
|
|
$all_data['minimum_order_quantity'] = $minimum_order_quantity;
|
|
|
- if ($all_data['sampling_start_time'] && strtotime(date('Y-m-d', $all_data['sampling_start_time']). '23:59:59') < time()) return json_send(['code' => 'error', 'msg' => '采集开始时间必须大于当前时间']);
|
|
|
|
|
|
|
+ if ($all_data['sampling_start_time'] && strtotime(date('Y-m-d', $all_data['sampling_start_time']) . '23:59:59') < time()) return json_send(['code' => 'error', 'msg' => '采集开始时间必须大于当前时间']);
|
|
|
if ($all_data['sampling_end_time'] && $all_data['sampling_end_time'] < time()) return json_send(['code' => 'error', 'msg' => '采集结束时间必须大于当前时间']);
|
|
if ($all_data['sampling_end_time'] && $all_data['sampling_end_time'] < time()) return json_send(['code' => 'error', 'msg' => '采集结束时间必须大于当前时间']);
|
|
|
//查询是否存在
|
|
//查询是否存在
|
|
|
$map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
|
|
$map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
|