|
|
@@ -186,14 +186,12 @@ class LowPriceGoods extends Controller
|
|
|
$product_brand = request('product_brand', '');
|
|
|
$product_keyword = request('product_keyword', '');
|
|
|
$product_specs = request('product_specs', '');
|
|
|
+ $all_data['platform'] = request('platform', '');
|
|
|
$all_data['product_specs'] = $product_specs;
|
|
|
$all_data['product_brand'] = $product_brand;
|
|
|
$all_data['product_keyword'] = $product_keyword;
|
|
|
- $enable_full_quantity = request('enable_full_quantity', 1); //全量,0启用,1禁用
|
|
|
+ $enable_full_quantity = request('enable_full_quantity', 0); //全量,0启用,1禁用
|
|
|
$all_data['enable_full_quantity'] = $enable_full_quantity;
|
|
|
- if ($enable_full_quantity == 1 && !isset($all_data['product_specs'])) {
|
|
|
- return json_send(['code' => 'error', 'msg' => '非全量清洗时,商品规格不能为空']);
|
|
|
- }
|
|
|
if (trim($product_keyword) != '') {
|
|
|
$product_keyword_count = count(explode(',', $product_keyword));
|
|
|
if ($product_keyword_count > 5) {
|
|
|
@@ -210,7 +208,8 @@ class LowPriceGoods extends Controller
|
|
|
$specify_responsible_person = request('specify_responsible_person', '0');
|
|
|
$all_data['specify_responsible_person'] = $specify_responsible_person;
|
|
|
//查询是否存在
|
|
|
- $map = ['product_brand' => $all_data['product_brand'], 'product_name' => $all_data['product_name'],'suggested_price'=> $all_data['suggested_price']];
|
|
|
+ $map = ['product_name' => $all_data['product_name'],'suggested_price'=> $all_data['suggested_price']];
|
|
|
+ if ($all_data['product_brand'] !='') $map['product_brand'] = $all_data['product_brand'];
|
|
|
if (isset($all_data['product_specs']) && $all_data['product_specs'] != '') {
|
|
|
$map['product_specs'] = $all_data['product_specs'];
|
|
|
}
|
|
|
@@ -222,7 +221,7 @@ class LowPriceGoods extends Controller
|
|
|
$all_data['company_id'] = $admin_company_id;
|
|
|
}
|
|
|
$data = $LowPriceGoodsModel->where($map)->first();
|
|
|
- if (!empty($data) && $enable_full_quantity == 1) {
|
|
|
+ if (!empty($data)) {
|
|
|
//继续校验规格是否存在
|
|
|
$product_specs_tring = $all_data['product_specs'];
|
|
|
$product_specs = $product_specs_tring ? explode(',', $product_specs_tring) : '';
|
|
|
@@ -233,17 +232,20 @@ class LowPriceGoods extends Controller
|
|
|
$platforms = $platforms ? array_unique($platforms) : '';
|
|
|
|
|
|
$platform_data = $LowPriceGoodsModel->platform_index_data();
|
|
|
+ $map_where = ['product_name' => $all_data['product_name'], 'suggested_price' => $all_data['suggested_price'], 'status' => '0', 'company_id' => $all_data['company_id']];
|
|
|
+ if ($product_brand != '') $map_where['product_brand'] = $product_brand;
|
|
|
foreach ($platforms as $platform) {
|
|
|
$product_specs_log = $LowPriceGoodsModel
|
|
|
->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
- ->where(['product_brand' => $product_brand, 'product_name' => $all_data['product_name'],'suggested_price'=> $all_data['suggested_price'], 'status' => '0'])
|
|
|
+ ->where($map_where)
|
|
|
->where(function ($query) use ($product_specs) {
|
|
|
// 平台条件(固定)
|
|
|
$query->where(function ($query_li) use ($product_specs) {
|
|
|
-
|
|
|
- foreach ($product_specs as $product_spec) {
|
|
|
- if (empty($product_specs)) continue;
|
|
|
- $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
|
|
|
+ if (!empty($product_specs)) {
|
|
|
+ foreach ($product_specs as $product_spec) {
|
|
|
+ if (empty($product_specs)) continue;
|
|
|
+ $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
})->first();
|
|
|
@@ -252,21 +254,6 @@ class LowPriceGoods extends Controller
|
|
|
return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格记录']);
|
|
|
}
|
|
|
}
|
|
|
- } else if (!empty($data) && $enable_full_quantity == 0) {
|
|
|
- $platforms = $platform_string ? explode(',', $platform_string) : '';
|
|
|
- $platforms = $platforms ? array_unique($platforms) : '';
|
|
|
-
|
|
|
- $platform_data = $LowPriceGoodsModel->platform_index_data();
|
|
|
- foreach ($platforms as $platform) {
|
|
|
- $product_specs_log = $LowPriceGoodsModel
|
|
|
- ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
- ->where(['product_brand' => $product_brand, 'product_name' => $all_data['product_name'],'suggested_price'=> $all_data['suggested_price'], 'status' => '0'])
|
|
|
- ->first();
|
|
|
- $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
|
|
|
- if (!empty($product_specs_log)) {
|
|
|
- return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品记录']);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
// 写入数据表
|
|
|
$result = $LowPriceGoodsModel->addLowProduct($all_data);
|
|
|
@@ -302,14 +289,12 @@ class LowPriceGoods extends Controller
|
|
|
$product_brand = request('product_brand', '');
|
|
|
$product_keyword = request('product_keyword', '');
|
|
|
$product_specs = request('product_specs', '');
|
|
|
+ $all_data['platform'] = request('platform', '');
|
|
|
$all_data['product_specs'] = $product_specs;
|
|
|
$all_data['product_brand'] = $product_brand;
|
|
|
$all_data['product_keyword'] = $product_keyword;
|
|
|
- $enable_full_quantity = request('enable_full_quantity', 1); //全量,0启用,1禁用
|
|
|
+ $enable_full_quantity = request('enable_full_quantity', 0); //全量,0启用,1禁用
|
|
|
$all_data['enable_full_quantity'] = $enable_full_quantity;
|
|
|
- if ($enable_full_quantity == 1 && !isset($all_data['product_specs'])) {
|
|
|
- return json_send(['code' => 'error', 'msg' => '非全量清洗时,商品规格不能为空']);
|
|
|
- }
|
|
|
if (trim($product_keyword) != '') {
|
|
|
$product_keyword_count = count(explode(',', $product_keyword));
|
|
|
if ($product_keyword_count > 5) {
|
|
|
@@ -326,17 +311,20 @@ class LowPriceGoods extends Controller
|
|
|
$specify_responsible_person = request('specify_responsible_person', '0');
|
|
|
$all_data['specify_responsible_person'] = $specify_responsible_person;
|
|
|
//查询是否存在
|
|
|
- $map = ['product_brand' => $all_data['product_brand'], 'product_name' => $all_data['product_name'],'suggested_price'=> $all_data['suggested_price']];
|
|
|
+ $map = ['product_name' => $all_data['product_name'],'suggested_price'=> $all_data['suggested_price']];
|
|
|
+ if ($all_data['product_brand'] !='') $map['product_brand'] = $all_data['product_brand'];
|
|
|
if (isset($all_data['product_specs']) && $all_data['product_specs'] != '') {
|
|
|
$map['product_specs'] = $all_data['product_specs'];
|
|
|
}
|
|
|
if ($is_admin != 1 && $company_id != 0) {
|
|
|
$map['company_id'] = $company_id;
|
|
|
+ $all_data['company_id'] = $company_id;
|
|
|
} else {
|
|
|
$map['company_id'] = $admin_company_id;
|
|
|
+ $all_data['company_id'] = $admin_company_id;
|
|
|
}
|
|
|
$data = $LowPriceGoodsModel->where($map)->first();
|
|
|
- if (!empty($data) && $enable_full_quantity == 1) {
|
|
|
+ if (!empty($data)) {
|
|
|
//继续校验规格是否存在
|
|
|
$product_specs_tring = $all_data['product_specs'];
|
|
|
$product_specs = $product_specs_tring ? explode(',', $product_specs_tring) : '';
|
|
|
@@ -347,18 +335,21 @@ class LowPriceGoods extends Controller
|
|
|
$platforms = $platforms ? array_unique($platforms) : '';
|
|
|
|
|
|
$platform_data = $LowPriceGoodsModel->platform_index_data();
|
|
|
+ $map_where = ['product_brand' => $product_brand, 'product_name' => $all_data['product_name'],'suggested_price'=> $all_data['suggested_price'], 'status' => '0','company_id' => $all_data['company_id']];
|
|
|
+ if ($product_brand != '') $map_where['product_brand'] = $product_brand;
|
|
|
foreach ($platforms as $platform) {
|
|
|
$product_specs_log = $LowPriceGoodsModel
|
|
|
->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
- ->where(['product_brand' => $product_brand, 'product_name' => $all_data['product_name'],'suggested_price'=> $all_data['suggested_price'], 'status' => '0'])
|
|
|
+ ->where($map_where)
|
|
|
->where('id', '!=', $id)
|
|
|
->where(function ($query) use ($product_specs) {
|
|
|
// 平台条件(固定)
|
|
|
$query->where(function ($query_li) use ($product_specs) {
|
|
|
-
|
|
|
- foreach ($product_specs as $product_spec) {
|
|
|
- if (empty($product_specs)) continue;
|
|
|
- $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
|
|
|
+ if (!empty($product_specs)) {
|
|
|
+ foreach ($product_specs as $product_spec) {
|
|
|
+ if (empty($product_specs)) continue;
|
|
|
+ $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
})->first();
|
|
|
@@ -367,21 +358,6 @@ class LowPriceGoods extends Controller
|
|
|
return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格记录']);
|
|
|
}
|
|
|
}
|
|
|
- } else if (!empty($data) && $enable_full_quantity == 0) {
|
|
|
- $platforms = $platform_string ? explode(',', $platform_string) : '';
|
|
|
- $platforms = $platforms ? array_unique($platforms) : '';
|
|
|
-
|
|
|
- $platform_data = $LowPriceGoodsModel->platform_index_data();
|
|
|
- foreach ($platforms as $platform) {
|
|
|
- $product_specs_log = $LowPriceGoodsModel
|
|
|
- ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
- ->where(['product_brand' => $product_brand, 'product_name' => $all_data['product_name'],'suggested_price'=> $all_data['suggested_price'], 'status' => '0'])
|
|
|
- ->first();
|
|
|
- $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
|
|
|
- if (!empty($product_specs_log)) {
|
|
|
- return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品记录']);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
// 更新数据表
|
|
|
$where = ['id' => $id];
|
|
|
@@ -448,7 +424,7 @@ class LowPriceGoods extends Controller
|
|
|
}
|
|
|
$LowProduct = $LowPriceGoodsModel->where($where)->first();
|
|
|
if (!$LowProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
|
|
|
- if (!empty($LowProduct) && $LowProduct->enable_full_quantity == 1) {
|
|
|
+ if (!empty($LowProduct)) {
|
|
|
//继续校验规格是否存在
|
|
|
$product_specs_tring = $LowProduct->product_specs;
|
|
|
$product_specs = $product_specs_tring ? explode(',', $product_specs_tring) : '';
|
|
|
@@ -463,15 +439,16 @@ class LowPriceGoods extends Controller
|
|
|
foreach ($platforms as $platform) {
|
|
|
$product_specs_log = $LowPriceGoodsModel
|
|
|
->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
- ->where(['product_brand' => $LowProduct->product_brand, 'product_name' => $LowProduct->product_name,'suggested_price'=> $LowProduct->suggested_price, 'status' => '0'])
|
|
|
+ ->where(['product_brand' => $LowProduct->product_brand, 'product_name' => $LowProduct->product_name, 'suggested_price' => $LowProduct->suggested_price, 'status' => '0', 'company_id' => $LowProduct->company_id])
|
|
|
->where('id', '!=', $id)
|
|
|
->where(function ($query) use ($product_specs) {
|
|
|
// 平台条件(固定)
|
|
|
$query->where(function ($query_li) use ($product_specs) {
|
|
|
-
|
|
|
- foreach ($product_specs as $product_spec) {
|
|
|
- if (empty($product_specs)) continue;
|
|
|
- $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
|
|
|
+ if (!empty($product_specs)) {
|
|
|
+ foreach ($product_specs as $product_spec) {
|
|
|
+ if (empty($product_specs)) continue;
|
|
|
+ $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
})->first();
|
|
|
@@ -480,22 +457,6 @@ class LowPriceGoods extends Controller
|
|
|
return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格启用记录']);
|
|
|
}
|
|
|
}
|
|
|
- } else if (!empty($LowProduct) && $LowProduct->enable_full_quantity == 0) {
|
|
|
- $platform_string = $LowProduct->platform;
|
|
|
- $platforms = $platform_string ? explode(',', $platform_string) : '';
|
|
|
- $platforms = $platforms ? array_unique($platforms) : '';
|
|
|
-
|
|
|
- $platform_data = $LowPriceGoodsModel->platform_index_data();
|
|
|
- foreach ($platforms as $platform) {
|
|
|
- $product_specs_log = $LowPriceGoodsModel
|
|
|
- ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
- ->where(['product_brand' => $LowProduct->product_brand, 'product_name' => $LowProduct->product_name,'suggested_price'=> $LowProduct->suggested_price, 'status' => '0'])
|
|
|
- ->where('id', '!=', $id)->first();
|
|
|
- $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
|
|
|
- if (!empty($product_specs_log)) {
|
|
|
- return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品启用记录']);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
// 执行修改
|
|
|
$result = $LowPriceGoodsModel->changeStatus($LowProduct, $status);
|