|
|
@@ -8,6 +8,7 @@ use App\Models\Manager\WashConfig\ViolationProduct as ViolationProductModel;
|
|
|
use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
|
|
|
use App\Models\Manager\WashConfig\ViolationProductCompany as ViolationProductCompanyModel;
|
|
|
use App\Models\Manager\WashConfig\ProductCategory as ProductCategoryModel;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
|
* 数据清洗-违规产品配置
|
|
|
@@ -24,7 +25,7 @@ class ViolationProduct extends Controller
|
|
|
* @date 2025-12-03
|
|
|
*
|
|
|
*/
|
|
|
- public function list(Request $request, ViolationProductModel $ViolationProductModel,ViolationStoreModel $ViolationStoreModel,ViolationProductCompanyModel $ViolationProductCompanyModel, ProductCategoryModel $ProductCategoryModel)
|
|
|
+ public function list(Request $request, ViolationProductModel $ViolationProductModel, ViolationStoreModel $ViolationStoreModel, ViolationProductCompanyModel $ViolationProductCompanyModel, ProductCategoryModel $ProductCategoryModel)
|
|
|
{
|
|
|
$request->scene('list')->validate();
|
|
|
// 查询条件
|
|
|
@@ -45,8 +46,8 @@ class ViolationProduct extends Controller
|
|
|
if (is_numeric($status)) $map[] = ['status', '=', $status];
|
|
|
if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
|
|
|
if ($platform) $map[] = ['platform', 'like', "%$platform%"];
|
|
|
- if ($store_scope) $map[] = ['store_scope', '=',$store_scope];
|
|
|
- if ($company_scope) $map[] = ['company_scope', '=',$company_scope];
|
|
|
+ if ($store_scope) $map[] = ['store_scope', '=', $store_scope];
|
|
|
+ if ($company_scope) $map[] = ['company_scope', '=', $company_scope];
|
|
|
if ($category_id) $map[] = ['category_id', '=', $category_id];
|
|
|
// 查询数据
|
|
|
$result = $ViolationProductModel->query()
|
|
|
@@ -55,25 +56,25 @@ class ViolationProduct extends Controller
|
|
|
->paginate($limit)->toarray();
|
|
|
// 分配数据
|
|
|
if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
|
|
|
- if(isset($result['data']) && count($result['data']) > 0){
|
|
|
+ if (isset($result['data']) && count($result['data']) > 0) {
|
|
|
foreach ($result['data'] as $key => $value) {
|
|
|
- $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',',$value['platform']) : '';
|
|
|
- $category_name = $value['category_id'] > 0 ? $ProductCategoryModel->where('id', $value['category_id'])->value('name'):'';
|
|
|
- $result['data'][$key]['category_name'] = $category_name;
|
|
|
+ $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : '';
|
|
|
+ $category_name = $value['category_id'] > 0 ? $ProductCategoryModel->where('id', $value['category_id'])->value('name') : '';
|
|
|
+ $result['data'][$key]['category_name'] = $category_name;
|
|
|
//查询店铺名称
|
|
|
- if(trim($value['store_scope']) == ''){
|
|
|
- $result['data'][$key]['store_name'] =['全部店铺'];
|
|
|
- }else{
|
|
|
+ if (trim($value['store_scope']) == '') {
|
|
|
+ $result['data'][$key]['store_name'] = ['全部店铺'];
|
|
|
+ } else {
|
|
|
$result['data'][$key]['store_name'] = '';
|
|
|
}
|
|
|
//查询公司名称
|
|
|
- if($value['company_scope'] == '1'){
|
|
|
- $result['data'][$key]['company_name'] =['全部公司'];
|
|
|
- }else{
|
|
|
- $company_data = $ViolationProductCompanyModel->where('violation_product_logid',$value['id'])
|
|
|
- ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_violation_product_company.company_id')
|
|
|
- ->select(['washconfig_violation_store.id','washconfig_violation_store.company_name','washconfig_violation_product_company.company_id'])->get()->toArray();
|
|
|
- $result['data'][$key]['company_name'] = !empty($company_data) ? array_column($company_data,'company_name') : '';
|
|
|
+ if ($value['company_scope'] == '1') {
|
|
|
+ $result['data'][$key]['company_name'] = ['全部公司'];
|
|
|
+ } else {
|
|
|
+ $company_data = $ViolationProductCompanyModel->where('violation_product_logid', $value['id'])
|
|
|
+ ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_violation_product_company.company_id')
|
|
|
+ ->select(['washconfig_violation_store.id', 'washconfig_violation_store.company_name', 'washconfig_violation_product_company.company_id'])->get()->toArray();
|
|
|
+ $result['data'][$key]['company_name'] = !empty($company_data) ? array_column($company_data, 'company_name') : '';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -87,7 +88,7 @@ class ViolationProduct extends Controller
|
|
|
* @version 1.0
|
|
|
* @date 2025-12-03
|
|
|
*/
|
|
|
- public function detail(Request $request, ViolationProductModel $ViolationProductModel,ViolationProductCompanyModel $ViolationProductCompanyModel, ProductCategoryModel $ProductCategoryModel)
|
|
|
+ public function detail(Request $request, ViolationProductModel $ViolationProductModel, ViolationProductCompanyModel $ViolationProductCompanyModel, ProductCategoryModel $ProductCategoryModel)
|
|
|
{
|
|
|
$request->scene('detail')->validate();
|
|
|
// 接收参数
|
|
|
@@ -96,15 +97,15 @@ class ViolationProduct extends Controller
|
|
|
$data = $ViolationProductModel->where($map)->first();
|
|
|
if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
|
|
|
//查询店铺名称
|
|
|
- if(trim($data['store_scope']) == ''){
|
|
|
+ if (trim($data['store_scope']) == '') {
|
|
|
$data['store_name'] = ['全部店铺'];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$data['store_name'] = '';
|
|
|
}
|
|
|
//查询公司名称
|
|
|
if ($data->company_scope == '1') {
|
|
|
$data->company_name = ['全部公司'];
|
|
|
- $data->company_ids ='';
|
|
|
+ $data->company_ids = '';
|
|
|
} else {
|
|
|
$company_data = $ViolationProductCompanyModel->where('violation_product_logid', $data->id)
|
|
|
->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_violation_product_company.company_id')
|
|
|
@@ -112,8 +113,8 @@ class ViolationProduct extends Controller
|
|
|
$data->company_name = !empty($company_data) ? array_column($company_data, 'company_name') : '';
|
|
|
$data->company_ids = !empty($company_data) ? array_column($company_data, 'company_id') : '';
|
|
|
}
|
|
|
- $data->platform = isset($data->platform) ? explode(',',$data->platform) : '';
|
|
|
- $data->category_name = $data->category_id > 0 ? $ProductCategoryModel->where('id', $data->category_id)->value('name'):'';
|
|
|
+ $data->platform = isset($data->platform) ? explode(',', $data->platform) : '';
|
|
|
+ $data->category_name = $data->category_id > 0 ? $ProductCategoryModel->where('id', $data->category_id)->value('name') : '';
|
|
|
// 加载模板
|
|
|
return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
|
|
|
}
|
|
|
@@ -143,16 +144,21 @@ class ViolationProduct extends Controller
|
|
|
$sampling_start_time = request('sampling_start_time', '');
|
|
|
$sampling_end_time = request('sampling_end_time', '');
|
|
|
$all_data['sampling_cycle'] = $sampling_cycle;
|
|
|
- $all_data['sampling_start_time'] = strtotime($sampling_start_time.'00:00:00');
|
|
|
- $all_data['sampling_end_time'] = strtotime($sampling_end_time.'23:59:59');
|
|
|
+ $all_data['sampling_start_time'] = strtotime($sampling_start_time . '00:00:00');
|
|
|
+ $all_data['sampling_end_time'] = strtotime($sampling_end_time . '23:59:59');
|
|
|
//查询是否存在
|
|
|
- $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']];
|
|
|
$data = $ViolationProductModel->where($map)->first();
|
|
|
if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
|
|
|
// 写入数据表
|
|
|
$result = $ViolationProductModel->addViolationProduct($all_data);
|
|
|
// 如果操作失败
|
|
|
if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
|
|
|
+ // 记录行为
|
|
|
+ $admin_id = request('access_token.uid', 0); //用户ID
|
|
|
+ $table_name = $ViolationProductModel->getTable();
|
|
|
+ $notes_type = 1; //操作类型,1添加,2修改,3=删除
|
|
|
+ $this->addAdminHistory('清洗配置-禁止商品管理', $admin_id, $table_name, $notes_type, [], $all_data, '新增了违规商品' . $all_data['product_name'] . '信息');
|
|
|
// 告知结果
|
|
|
return json_send(['code' => 'success', 'msg' => '新增成功']);
|
|
|
}
|
|
|
@@ -184,17 +190,24 @@ class ViolationProduct extends Controller
|
|
|
$sampling_start_time = request('sampling_start_time', '');
|
|
|
$sampling_end_time = request('sampling_end_time', '');
|
|
|
$all_data['sampling_cycle'] = $sampling_cycle;
|
|
|
- $all_data['sampling_start_time'] = strtotime($sampling_start_time.'00:00:00');
|
|
|
- $all_data['sampling_end_time'] = strtotime($sampling_end_time.'23:59:59');
|
|
|
+ $all_data['sampling_start_time'] = strtotime($sampling_start_time . '00:00:00');
|
|
|
+ $all_data['sampling_end_time'] = strtotime($sampling_end_time . '23:59:59');
|
|
|
//查询是否存在
|
|
|
- $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']];
|
|
|
$data = $ViolationProductModel->where($map)->where('id', '!=', $id)->first();
|
|
|
if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
|
|
|
// 更新数据表
|
|
|
$where = ['id' => $id];
|
|
|
- $result = $ViolationProductModel->updateViolationProduct($where, $all_data);
|
|
|
+ $ViolationProduct = $ViolationProductModel->where($where)->first();
|
|
|
+ if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
|
|
|
+ $result = $ViolationProductModel->editViolationProduct_content($ViolationProduct, $all_data);
|
|
|
// 如果操作失败
|
|
|
if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
|
|
|
+ // 记录行为
|
|
|
+ $admin_id = request('access_token.uid', 0); //用户ID
|
|
|
+ $table_name = $ViolationProductModel->getTable();
|
|
|
+ $notes_type = 2; //操作类型,1添加,2修改,3=删除
|
|
|
+ $this->addAdminHistory('清洗配置-禁止商品管理', $admin_id, $table_name, $notes_type, $ViolationProduct->toarray(), $all_data, '修改了违规商品' . $ViolationProduct->product_name . '信息');
|
|
|
// 告知结果
|
|
|
return json_send(['code' => 'success', 'msg' => '修改成功']);
|
|
|
}
|
|
|
@@ -215,10 +228,17 @@ class ViolationProduct extends Controller
|
|
|
$status = request('status', 0);
|
|
|
// 查询用户
|
|
|
$where = ['id' => $id];
|
|
|
+ $ViolationProduct = $ViolationProductModel->where($where)->first();
|
|
|
+ if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
|
|
|
// 执行修改
|
|
|
- $result = $ViolationProductModel->changeStatus($where, $status);
|
|
|
+ $result = $ViolationProductModel->changeStatus($ViolationProduct, $status);
|
|
|
// 提示新增失败
|
|
|
if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
|
|
|
+ // 记录行为
|
|
|
+ $admin_id = request('access_token.uid', 0); //用户ID
|
|
|
+ $table_name = $ViolationProductModel->getTable();
|
|
|
+ $notes_type = 2; //操作类型,1添加,2修改,3=删除
|
|
|
+ $this->addAdminHistory('清洗配置-禁止商品管理', $admin_id, $table_name, $notes_type,[],['status'=> $status], '修改了违规商品' . $ViolationProduct->product_name . '状态');
|
|
|
// 告知结果
|
|
|
return json_send(['code' => 'success', 'msg' => '设置成功']);
|
|
|
}
|
|
|
@@ -240,10 +260,31 @@ class ViolationProduct extends Controller
|
|
|
// 查询用户
|
|
|
$where = ['id' => $id];
|
|
|
// 执行删除
|
|
|
- $result = $ViolationProductModel->deleteViolationProduct($where);
|
|
|
- // 提示删除失败
|
|
|
- if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
|
|
|
- // 告知结果
|
|
|
- return json_send(['code' => 'success', 'msg' => '删除成功']);
|
|
|
+ $ViolationProduct = $ViolationProductModel->where($where)->first();
|
|
|
+ if (!$ViolationProduct) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $ViolationProductCompanyModel = new ViolationProductCompanyModel();
|
|
|
+ $company_id_log = $ViolationProductCompanyModel->where('violation_product_logid', $ViolationProduct->id)->get();
|
|
|
+ if (!empty($company_id_log)) {
|
|
|
+ $ViolationProductCompanyModel->where('violation_product_logid', $ViolationProduct->id)->delete();
|
|
|
+ }
|
|
|
+ $ViolationProduct->delete();
|
|
|
+ // 记录行为
|
|
|
+ $admin_id = request('access_token.uid', 0); //用户ID
|
|
|
+ $table_name = $ViolationProductModel->getTable();
|
|
|
+ $notes_type = 3; //操作类型,1添加,2修改,3=删除
|
|
|
+ $this->addAdminHistory('清洗配置-禁止商品管理', $admin_id, $table_name, $notes_type, $ViolationProduct->toarray(), [], '删除了违规商品' . $ViolationProduct->product_name . '信息');
|
|
|
+ // 告知结果
|
|
|
+ DB::commit();
|
|
|
+ return json_send(['code' => 'success', 'msg' => '删除成功']);
|
|
|
+ // 成功处理...
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ // 错误处理...
|
|
|
+ return json_send(['code' => 'error', 'msg' => '删除失败']);
|
|
|
+ }
|
|
|
}
|
|
|
}
|