|
|
@@ -169,7 +169,7 @@ class ViolationProduct extends Controller
|
|
|
* @date 2025-12-03
|
|
|
*
|
|
|
*/
|
|
|
- public function add(Request $request, ViolationProductModel $ViolationProductModel )
|
|
|
+ public function add(Request $request, ViolationProductModel $ViolationProductModel)
|
|
|
{
|
|
|
$request->scene('add')->validate();
|
|
|
$admin_company_id = request('admin_company_id', '0');
|
|
|
@@ -198,7 +198,7 @@ class ViolationProduct extends Controller
|
|
|
$all_data['product_keyword'] = $product_keyword;
|
|
|
$enable_full_quantity = request('enable_full_quantity', 0); //全量,0启用,1禁用
|
|
|
$all_data['enable_full_quantity'] = $enable_full_quantity;
|
|
|
- if(trim($product_keyword) !=''){
|
|
|
+ if (trim($product_keyword) != '') {
|
|
|
$product_keyword_count = count(explode(',', $product_keyword));
|
|
|
if ($product_keyword_count > 5) {
|
|
|
return json_send(['code' => 'error', 'msg' => '商品关键词不能超过5个']);
|
|
|
@@ -215,7 +215,7 @@ class ViolationProduct extends Controller
|
|
|
$all_data['specify_responsible_person'] = $specify_responsible_person;
|
|
|
//查询是否存在
|
|
|
$map = ['product_name' => $all_data['product_name']];
|
|
|
- if ($all_data['product_brand'] !='') $map['product_brand'] = $all_data['product_brand'];
|
|
|
+ if ($all_data['product_brand'] != '') $map['product_brand'] = $all_data['product_brand'];
|
|
|
if ($is_admin != 1 && $company_id != 0) {
|
|
|
$map['company_id'] = $company_id;
|
|
|
$all_data['company_id'] = $company_id;
|
|
|
@@ -235,31 +235,33 @@ class ViolationProduct extends Controller
|
|
|
$platforms = $platforms ? array_unique($platforms) : '';
|
|
|
|
|
|
$platform_data = $ViolationProductModel->platform_index_data();
|
|
|
- $map_where = ['product_name' => $all_data['product_name'], 'status' => '0','company_id' => $all_data['company_id']];
|
|
|
+ $map_where = ['product_name' => $all_data['product_name'], 'status' => '0', 'company_id' => $all_data['company_id']];
|
|
|
if ($product_brand != '') $map_where['product_brand'] = $product_brand;
|
|
|
- foreach ($platforms as $platform) {
|
|
|
- $product_specs_log = $ViolationProductModel
|
|
|
- ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
- ->where($map_where)
|
|
|
- ->where(function ($query) use ($product_specs) {
|
|
|
- // 平台条件(固定)
|
|
|
- $query->where(function ($query_li) use ($product_specs) {
|
|
|
- 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]);
|
|
|
+ if (!empty($platform_data)) {
|
|
|
+ foreach ($platforms as $platform) {
|
|
|
+ $product_specs_log = $ViolationProductModel
|
|
|
+ ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
+ ->where($map_where)
|
|
|
+ ->where(function ($query) use ($product_specs) {
|
|
|
+ // 平台条件(固定)
|
|
|
+ $query->where(function ($query_li) use ($product_specs) {
|
|
|
+ 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();
|
|
|
- $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
|
|
|
- if (!empty($product_specs_log)) {
|
|
|
- return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格记录']);
|
|
|
+ });
|
|
|
+ })->first();
|
|
|
+ $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
|
|
|
+ if (!empty($product_specs_log)) {
|
|
|
+ return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格记录']);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 写入数据表
|
|
|
-
|
|
|
+
|
|
|
$result = $ViolationProductModel->addViolationProduct($all_data);
|
|
|
// 如果操作失败
|
|
|
if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
|
|
|
@@ -298,7 +300,7 @@ class ViolationProduct extends Controller
|
|
|
$all_data['product_keyword'] = $product_keyword;
|
|
|
$enable_full_quantity = request('enable_full_quantity', 0); //全量,0启用,1禁用
|
|
|
$all_data['enable_full_quantity'] = $enable_full_quantity;
|
|
|
- if(trim($product_keyword) !=''){
|
|
|
+ if (trim($product_keyword) != '') {
|
|
|
$product_keyword_count = count(explode(',', $product_keyword));
|
|
|
if ($product_keyword_count > 5) {
|
|
|
return json_send(['code' => 'error', 'msg' => '商品关键词不能超过5个']);
|
|
|
@@ -315,7 +317,7 @@ class ViolationProduct extends Controller
|
|
|
$all_data['specify_responsible_person'] = $specify_responsible_person;
|
|
|
//查询是否存在
|
|
|
$map = ['product_name' => $all_data['product_name']];
|
|
|
- if ($all_data['product_brand'] !='') $map['product_brand'] = $all_data['product_brand'];
|
|
|
+ if ($all_data['product_brand'] != '') $map['product_brand'] = $all_data['product_brand'];
|
|
|
if ($is_admin != 1 && $company_id != 0) {
|
|
|
$map['company_id'] = $company_id;
|
|
|
$all_data['company_id'] = $company_id;
|
|
|
@@ -335,27 +337,29 @@ class ViolationProduct extends Controller
|
|
|
$platforms = $platforms ? array_unique($platforms) : '';
|
|
|
|
|
|
$platform_data = $ViolationProductModel->platform_index_data();
|
|
|
- $map_where = ['product_name' => $all_data['product_name'], 'status' => '0','company_id' => $all_data['company_id']];
|
|
|
+ $map_where = ['product_name' => $all_data['product_name'], 'status' => '0', 'company_id' => $all_data['company_id']];
|
|
|
if ($product_brand != '') $map_where['product_brand'] = $product_brand;
|
|
|
- foreach ($platforms as $platform) {
|
|
|
- $product_specs_log = $ViolationProductModel
|
|
|
- ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
- ->where($map_where)
|
|
|
- ->where('id', '!=', $id)
|
|
|
- ->where(function ($query) use ($product_specs) {
|
|
|
- // 平台条件(固定)
|
|
|
- $query->where(function ($query_li) use ($product_specs) {
|
|
|
- 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]);
|
|
|
+ if (!empty($platform_data)) {
|
|
|
+ foreach ($platforms as $platform) {
|
|
|
+ $product_specs_log = $ViolationProductModel
|
|
|
+ ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
+ ->where($map_where)
|
|
|
+ ->where('id', '!=', $id)
|
|
|
+ ->where(function ($query) use ($product_specs) {
|
|
|
+ // 平台条件(固定)
|
|
|
+ $query->where(function ($query_li) use ($product_specs) {
|
|
|
+ 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();
|
|
|
- $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
|
|
|
- if (!empty($product_specs_log)) {
|
|
|
- return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格记录']);
|
|
|
+ });
|
|
|
+ })->first();
|
|
|
+ $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
|
|
|
+ if (!empty($product_specs_log)) {
|
|
|
+ return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格记录']);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -427,27 +431,30 @@ class ViolationProduct extends Controller
|
|
|
$platforms = $platforms ? array_unique($platforms) : '';
|
|
|
|
|
|
$platform_data = $ViolationProductModel->platform_index_data();
|
|
|
- foreach ($platforms as $platform) {
|
|
|
- $product_specs_log = $ViolationProductModel
|
|
|
- ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
- ->where(['product_brand' => $ViolationProduct->product_brand, 'product_name' => $ViolationProduct->product_name, 'status' => '0', 'company_id' => $ViolationProduct->company_id])
|
|
|
- ->where('id', '!=', $id)
|
|
|
- ->where(function ($query) use ($product_specs) {
|
|
|
- // 平台条件(固定)
|
|
|
- $query->where(function ($query_li) use ($product_specs) {
|
|
|
- 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]);
|
|
|
+ if (!empty($platform_data)) {
|
|
|
+ foreach ($platforms as $platform) {
|
|
|
+ $product_specs_log = $ViolationProductModel
|
|
|
+ ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
|
|
|
+ ->where(['product_brand' => $ViolationProduct->product_brand, 'product_name' => $ViolationProduct->product_name, 'status' => '0', 'company_id' => $ViolationProduct->company_id])
|
|
|
+ ->where('id', '!=', $id)
|
|
|
+ ->where(function ($query) use ($product_specs) {
|
|
|
+ // 平台条件(固定)
|
|
|
+ $query->where(function ($query_li) use ($product_specs) {
|
|
|
+ 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();
|
|
|
- $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
|
|
|
- if (!empty($product_specs_log)) {
|
|
|
- return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格启用记录']);
|
|
|
+ });
|
|
|
+ })->first();
|
|
|
+ $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
|
|
|
+ if (!empty($product_specs_log)) {
|
|
|
+ return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格启用记录']);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
// 执行修改
|
|
|
$result = $ViolationProductModel->changeStatus($ViolationProduct, $status);
|
|
|
@@ -557,7 +564,7 @@ class ViolationProduct extends Controller
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* 导入Excel数据
|
|
|
* @author 唐远望
|
|
|
* @version 1.0
|
|
|
@@ -613,7 +620,7 @@ class ViolationProduct extends Controller
|
|
|
$insert_product_data['company_id'] = $admin_company_id;
|
|
|
}
|
|
|
$insert_product_data['product_name'] = $item[0]; // 商品名称
|
|
|
- $insert_product_data['category_id'] =$category_id; // 商品分类
|
|
|
+ $insert_product_data['category_id'] = $category_id; // 商品分类
|
|
|
$insert_product_data['product_specs'] = $item[2]; // 商品规格
|
|
|
$insert_product_data['platform'] = $platform_id_text != '' ? substr($platform_id_text, 0, -1) : '0'; // 平台:0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久
|
|
|
$insert_product_data['store_scope'] = ''; // 店铺范围(为空时全部,指定时为店铺ID多个逗号隔开)
|