|
|
@@ -13,6 +13,7 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
use App\Models\Manager\Process\ViolationProductMember as ViolationProductMemberModel;
|
|
|
use App\Models\Manager\Citys as CitysModel;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
|
* 违规处理-违规商品
|
|
|
@@ -70,7 +71,7 @@ class ViolationProduct extends Controller
|
|
|
if ($is_admin != 1 && $company_id != 0) {
|
|
|
$violation_product_where['company_id'] = $company_id;
|
|
|
} else {
|
|
|
- $violation_product_where['company_id'] = $admin_company_id;
|
|
|
+ $violation_product_where['company_id'] = $admin_company_id;
|
|
|
}
|
|
|
$ViolationProductModel = $ViolationProductModel->where($violation_product_where);
|
|
|
|
|
|
@@ -208,7 +209,7 @@ class ViolationProduct extends Controller
|
|
|
if ($is_admin != 1 && $company_id != 0) {
|
|
|
$violation_product_where['company_id'] = $company_id;
|
|
|
} else {
|
|
|
- $violation_product_where['company_id'] = $admin_company_id;
|
|
|
+ $violation_product_where['company_id'] = $admin_company_id;
|
|
|
}
|
|
|
$ViolationProductModel = $ViolationProductModel->where($violation_product_where);
|
|
|
|
|
|
@@ -467,7 +468,7 @@ class ViolationProduct extends Controller
|
|
|
if ($is_admin != 1 && $company_id != 0) {
|
|
|
$map['company_id'] = $company_id;
|
|
|
} else {
|
|
|
- $map['company_id'] = $admin_company_id;
|
|
|
+ $map['company_id'] = $admin_company_id;
|
|
|
}
|
|
|
$data = $ViolationProductModel->where($map)->first();
|
|
|
if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
|
|
|
@@ -511,8 +512,8 @@ class ViolationProduct extends Controller
|
|
|
$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;
|
|
|
+ $map['company_id'] = $admin_company_id;
|
|
|
+ $all_data['company_id'] = $admin_company_id;
|
|
|
}
|
|
|
$data = $ViolationProductModel->where($map)->first();
|
|
|
if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
|
|
|
@@ -550,8 +551,8 @@ class ViolationProduct extends Controller
|
|
|
$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;
|
|
|
+ $map['company_id'] = $admin_company_id;
|
|
|
+ $all_data['company_id'] = $admin_company_id;
|
|
|
}
|
|
|
$data = $ViolationProductModel->where($map)->where('id', '!=', $id)->first();
|
|
|
if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
|
|
|
@@ -692,7 +693,7 @@ class ViolationProduct extends Controller
|
|
|
} else {
|
|
|
$company_id = $admin_company_id;
|
|
|
}
|
|
|
- $message_data = ['page' => '1', 'limit' => 50, 'admin_id' => $admin_id, 'is_admin' => $is_admin,'company_id' => $company_id];
|
|
|
+ $message_data = ['page' => '1', 'limit' => 50, 'admin_id' => $admin_id, 'is_admin' => $is_admin, 'company_id' => $company_id];
|
|
|
ViolationProductJobs::dispatch($message_data);
|
|
|
// ViolationProductJobs::dispatchSync($message_data);
|
|
|
// 告知结果
|
|
|
@@ -760,7 +761,7 @@ class ViolationProduct extends Controller
|
|
|
* @date 2025-12-31
|
|
|
*
|
|
|
*/
|
|
|
- public function import_data(Request $request, ViolationProductModel $ViolationProductModel, EmployeeModel $EmployeeModel,CitysModel $CitysModel)
|
|
|
+ public function import_data(Request $request, ViolationProductModel $ViolationProductModel, EmployeeModel $EmployeeModel, CitysModel $CitysModel)
|
|
|
{
|
|
|
$request->scene('import_data')->validate();
|
|
|
$admin_company_id = request('admin_company_id', '0');
|
|
|
@@ -776,83 +777,94 @@ class ViolationProduct extends Controller
|
|
|
$result = $EmployeeModel->select(['id', 'name'])->get()->keyBy('name')->toarray();
|
|
|
$platform_data = $ViolationProductModel->platform_data();
|
|
|
$city_id_data = $CitysModel->get_city_id_list();
|
|
|
- foreach ($data as $key => $item) {
|
|
|
- if ($key < 2) continue;
|
|
|
- //强制必传参数校验
|
|
|
- $this->import_data_check($item);
|
|
|
- $first_responsible_person_id = [];
|
|
|
- $first_responsible_person_name = $item[0];
|
|
|
- if ($first_responsible_person_name) {
|
|
|
- $first_responsible_person_name = explode(',', $first_responsible_person_name);
|
|
|
- foreach ($first_responsible_person_name as $k => $v) {
|
|
|
- if (isset($result[$v])) {
|
|
|
- $first_responsible_person_id[] = $result[$v]['id'];
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ foreach ($data as $key => $item) {
|
|
|
+ if ($key < 2) continue;
|
|
|
+ //强制必传参数校验
|
|
|
+ $res_data = $this->import_data_check($key, $item);
|
|
|
+ if ($res_data) return json_send($res_data);
|
|
|
+ $first_responsible_person_id = [];
|
|
|
+ $first_responsible_person_name = $item[0];
|
|
|
+ if ($first_responsible_person_name) {
|
|
|
+ $first_responsible_person_name = explode(',', $first_responsible_person_name);
|
|
|
+ foreach ($first_responsible_person_name as $k => $v) {
|
|
|
+ if (isset($result[$v])) {
|
|
|
+ $first_responsible_person_id[] = $result[$v]['id'];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- $responsible_person_id = [];
|
|
|
- $responsible_person_name = $item[1];
|
|
|
- if ($responsible_person_name) {
|
|
|
- $responsible_person_name = explode(',', $responsible_person_name);
|
|
|
- foreach ($responsible_person_name as $k => $v) {
|
|
|
- if (isset($result[$v])) {
|
|
|
- $responsible_person_id[] = $result[$v]['id'];
|
|
|
+ $responsible_person_id = [];
|
|
|
+ $responsible_person_name = $item[1];
|
|
|
+ if ($responsible_person_name) {
|
|
|
+ $responsible_person_name = explode(',', $responsible_person_name);
|
|
|
+ foreach ($responsible_person_name as $k => $v) {
|
|
|
+ if (isset($result[$v])) {
|
|
|
+ $responsible_person_id[] = $result[$v]['id'];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- $source_responsible_person_id = [];
|
|
|
- $source_responsible_person_name = $item[15];
|
|
|
- if ($source_responsible_person_name) {
|
|
|
- $source_responsible_person_name = explode(',', $source_responsible_person_name);
|
|
|
- foreach ($source_responsible_person_name as $k => $v) {
|
|
|
- if (isset($result[$v])) {
|
|
|
- $source_responsible_person_id[] = $result[$v]['id'];
|
|
|
+ $source_responsible_person_id = [];
|
|
|
+ $source_responsible_person_name = $item[15];
|
|
|
+ if ($source_responsible_person_name) {
|
|
|
+ $source_responsible_person_name = explode(',', $source_responsible_person_name);
|
|
|
+ foreach ($source_responsible_person_name as $k => $v) {
|
|
|
+ if (isset($result[$v])) {
|
|
|
+ $source_responsible_person_id[] = $result[$v]['id'];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- $province_name = $item[13];
|
|
|
- if($province_name && !strpos($province_name,'省')){
|
|
|
- if(!in_array($province_name,['北京','天津','上海','重庆'])){
|
|
|
- $province_name = $province_name.'省';
|
|
|
+ $province_name = $item[13];
|
|
|
+ if ($province_name && !strpos($province_name, '省')) {
|
|
|
+ if (!in_array($province_name, ['北京', '天津', '上海', '重庆'])) {
|
|
|
+ $province_name = $province_name . '省';
|
|
|
+ }
|
|
|
}
|
|
|
+ $city_name = $item[14];
|
|
|
+ if ($city_name && !strpos($city_name, '市')) {
|
|
|
+ $city_name = $city_name . '市';
|
|
|
+ }
|
|
|
+ // 权限判断
|
|
|
+ if ($is_admin != 1 && $company_id != 0) {
|
|
|
+ $insert_product_data['company_id'] = $company_id;
|
|
|
+ } else {
|
|
|
+ $insert_product_data['company_id'] = $admin_company_id;
|
|
|
+ }
|
|
|
+ $insert_product_data['first_responsible_person'] = !empty($first_responsible_person_id) ? implode(',', $first_responsible_person_id) : ''; //第一责任人ID集合
|
|
|
+ $insert_product_data['responsible_person'] = !empty($responsible_person_id) ? implode(',', $responsible_person_id) : ''; //责任人ID集合
|
|
|
+ $insert_product_data['platform'] = isset($platform_data[$item[2]]) ? $platform_data[$item[2]] : '0'; // 平台
|
|
|
+ $insert_product_data['category_name'] = $item[3] ? $item[4] : ''; // 商品分类
|
|
|
+ $insert_product_data['product_name'] = $item[4]; // 商品名称
|
|
|
+ $insert_product_data['product_specs'] = $item[5]; // 商品规格
|
|
|
+ $insert_product_data['online_posting_count'] = isset($item[6]) ? $item[6] : 1; // 累计挂网次数
|
|
|
+ $insert_product_data['continuous_listing_count'] = isset($item[7]) ? $item[7] : 1; // 连续挂网次数
|
|
|
+ $insert_product_data['link_url'] = $item[8]; // 链接地址
|
|
|
+ $insert_product_data['store_name'] = $item[9]; // 店铺名称
|
|
|
+ $insert_product_data['company_name'] = $item[10]; // 公司名称
|
|
|
+ $insert_product_data['company_category_name'] = isset($item[11]) ? $item[11] : ''; // 公司分类
|
|
|
+ $insert_product_data['social_credit_code'] = $item[12]; // 信用代码
|
|
|
+ $insert_product_data['province_name'] = $item[13]; // 省份
|
|
|
+ $insert_product_data['province_id'] = isset($city_id_data[$province_name]) ? $city_id_data[$province_name]['id'] : 0; // 省份ID
|
|
|
+ $insert_product_data['city_name'] = $item[14]; // 城市
|
|
|
+ $insert_product_data['city_id'] = isset($city_id_data[$city_name]) ? $city_id_data[$city_name]['id'] : 0; // 城市ID
|
|
|
+ $insert_product_data['area_info'] = ''; // 详细地址
|
|
|
+ $insert_product_data['source_responsible_person'] = !empty($source_responsible_person_id) ? implode(',', $source_responsible_person_id) : ''; //溯源责任人ID集合
|
|
|
+ $insert_product_data['processing_status'] = 1; //处理状态1=待处理2=购买中3=已溯源4=回收凭据已上传5=已回收6=拒绝回收7=已下架8=无法处理
|
|
|
+ $insert_product_data['status'] = 0; //状态0=有效=无效
|
|
|
+ $insert_product_data['insert_time'] = time();
|
|
|
+ $insert_product_data['source_id'] = 0; // 原始数据ID
|
|
|
+ //插入数据
|
|
|
+ $ViolationProductModel->addViolationProduct($insert_product_data, true);
|
|
|
}
|
|
|
- $city_name = $item[14];
|
|
|
- if($city_name && !strpos($city_name,'市')){
|
|
|
- $city_name = $city_name.'市';
|
|
|
- }
|
|
|
- // 权限判断
|
|
|
- if ($is_admin != 1 && $company_id != 0) {
|
|
|
- $insert_product_data['company_id'] = $company_id;
|
|
|
- } else {
|
|
|
- $insert_product_data['company_id'] = $admin_company_id;
|
|
|
- }
|
|
|
- $insert_product_data['first_responsible_person'] = !empty($first_responsible_person_id) ? implode(',', $first_responsible_person_id) : ''; //第一责任人ID集合
|
|
|
- $insert_product_data['responsible_person'] = !empty($responsible_person_id) ? implode(',', $responsible_person_id) : ''; //责任人ID集合
|
|
|
- $insert_product_data['platform'] = isset($platform_data[$item[2]]) ? $platform_data[$item[2]] : '0'; // 平台
|
|
|
- $insert_product_data['category_name'] = $item[3] ? $item[4] : ''; // 商品分类
|
|
|
- $insert_product_data['product_name'] = $item[4]; // 商品名称
|
|
|
- $insert_product_data['product_specs'] = $item[5]; // 商品规格
|
|
|
- $insert_product_data['online_posting_count'] = isset($item[6]) ? $item[6] : 1; // 累计挂网次数
|
|
|
- $insert_product_data['continuous_listing_count'] = isset($item[7]) ? $item[7] : 1; // 连续挂网次数
|
|
|
- $insert_product_data['link_url'] = $item[8]; // 链接地址
|
|
|
- $insert_product_data['store_name'] = $item[9]; // 店铺名称
|
|
|
- $insert_product_data['company_name'] = $item[10]; // 公司名称
|
|
|
- $insert_product_data['company_category_name'] = isset($item[11]) ? $item[11] : ''; // 公司分类
|
|
|
- $insert_product_data['social_credit_code'] = $item[12]; // 信用代码
|
|
|
- $insert_product_data['province_name'] = $item[13]; // 省份
|
|
|
- $insert_product_data['province_id'] = isset($city_id_data[$province_name]) ? $city_id_data[$province_name]['id'] : 0; // 省份ID
|
|
|
- $insert_product_data['city_name'] = $item[14]; // 城市
|
|
|
- $insert_product_data['city_id'] = isset($city_id_data[$city_name]) ? $city_id_data[$city_name]['id'] : 0; // 城市ID
|
|
|
- $insert_product_data['area_info'] = ''; // 详细地址
|
|
|
- $insert_product_data['source_responsible_person'] = !empty($source_responsible_person_id) ? implode(',', $source_responsible_person_id) : ''; //溯源责任人ID集合
|
|
|
- $insert_product_data['processing_status'] = 1; //处理状态1=待处理2=购买中3=已溯源4=回收凭据已上传5=已回收6=拒绝回收7=已下架8=无法处理
|
|
|
- $insert_product_data['status'] = 0; //状态0=有效=无效
|
|
|
- $insert_product_data['insert_time'] = time();
|
|
|
- $insert_product_data['source_id'] = 0;// 原始数据ID
|
|
|
- //插入数据
|
|
|
- $ViolationProductModel->addViolationProduct($insert_product_data,true);
|
|
|
- }
|
|
|
- return json_send(['code' => 'success', 'msg' => '导入成功']);
|
|
|
+ DB::commit();
|
|
|
+ return json_send(['code' => 'success', 'msg' => '导入成功']);
|
|
|
+ // 成功处理...
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ // 错误处理...
|
|
|
+ return json_send(['code' => 'error', 'msg' => '导入失败', 'data' => $e->getMessage()]);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -862,34 +874,35 @@ class ViolationProduct extends Controller
|
|
|
* @date 2025-12-31
|
|
|
*
|
|
|
*/
|
|
|
- private function import_data_check($item)
|
|
|
+ private function import_data_check($key, $item)
|
|
|
{
|
|
|
- if ($item[2] == '') {
|
|
|
- return json_send(['code' => 'error', 'msg' => '平台不能为空']);
|
|
|
+ $key = $key + 1;
|
|
|
+ if (!$item[2]) {
|
|
|
+ return ['code' => 'error', 'msg' => "第{$key}行平台不能为空"];
|
|
|
}
|
|
|
- if ($item[4] == '') {
|
|
|
- return json_send(['code' => 'error', 'msg' => '商品名称不能为空']);
|
|
|
+ if (!$item[4]) {
|
|
|
+ return ['code' => 'error', 'msg' => "第{$key}行商品名称不能为空"];
|
|
|
}
|
|
|
- if ($item[5] == '') {
|
|
|
- return json_send(['code' => 'error', 'msg' => '商品规格不能为空']);
|
|
|
+ if (!$item[5]) {
|
|
|
+ return ['code' => 'error', 'msg' => "第{$key}行商品规格不能为空"];
|
|
|
}
|
|
|
- if ($item[6] == '') {
|
|
|
- return json_send(['code' => 'error', 'msg' => '链接地址不能为空']);
|
|
|
+ if (!$item[8]) {
|
|
|
+ return ['code' => 'error', 'msg' => "第{$key}行链接地址不能为空"];
|
|
|
}
|
|
|
- if ($item[9] == '') {
|
|
|
- return json_send(['code' => 'error', 'msg' => '店铺名称不能为空']);
|
|
|
+ if (!$item[9]) {
|
|
|
+ return ['code' => 'error', 'msg' => "第{$key}行店铺名称不能为空"];
|
|
|
}
|
|
|
- if ($item[10] == '') {
|
|
|
- return json_send(['code' => 'error', 'msg' => '公司名称不能为空']);
|
|
|
+ if (!$item[10]) {
|
|
|
+ return ['code' => 'error', 'msg' => "第{$key}行公司名称不能为空"];
|
|
|
}
|
|
|
- if ($item[11] == '') {
|
|
|
- return json_send(['code' => 'error', 'msg' => '信用代码不能为空']);
|
|
|
+ if (!$item[11]) {
|
|
|
+ return ['code' => 'error', 'msg' => "第{$key}行信用代码不能为空"];
|
|
|
}
|
|
|
- if ($item[12] == '') {
|
|
|
- return json_send(['code' => 'error', 'msg' => '省份不能为空']);
|
|
|
+ if (!$item[12]) {
|
|
|
+ return ['code' => 'error', 'msg' => "第{$key}行省份不能为空"];
|
|
|
}
|
|
|
- if ($item[13] == '') {
|
|
|
- return json_send(['code' => 'error', 'msg' => '城市不能为空']);
|
|
|
+ if (!$item[13]) {
|
|
|
+ return ['code' => 'error', 'msg' => "第{$key}行城市不能为空"];
|
|
|
}
|
|
|
}
|
|
|
}
|