|
@@ -10,9 +10,11 @@ use App\Models\Manager\Personnel\Employee as EmployeeModel;
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
|
|
+use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
use App\Models\Manager\Process\LowPriceGoodsMember as LowPriceGoodsMemberModel;
|
|
use App\Models\Manager\Process\LowPriceGoodsMember as LowPriceGoodsMemberModel;
|
|
|
use App\Models\manager\Process\LowPriceGoodsRecord as LowPriceGoodsRecordModel;
|
|
use App\Models\manager\Process\LowPriceGoodsRecord as LowPriceGoodsRecordModel;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
+use App\Models\Manager\Citys as CitysModel;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 违规处理-低价商品
|
|
* 违规处理-低价商品
|
|
@@ -336,7 +338,7 @@ class LowPriceGoods extends Controller
|
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
|
|
|
|
|
|
//合并单元格
|
|
//合并单元格
|
|
|
- $sheet->mergeCells('A1:S1');
|
|
|
|
|
|
|
+ $sheet->mergeCells('A1:U1');
|
|
|
$sheet->setCellValue('A1', '低价挂网商品导出(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
|
|
$sheet->setCellValue('A1', '低价挂网商品导出(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
|
|
|
// 获取合并后的单元格样式对象
|
|
// 获取合并后的单元格样式对象
|
|
|
$style = $sheet->getStyle('A1');
|
|
$style = $sheet->getStyle('A1');
|
|
@@ -680,7 +682,7 @@ class LowPriceGoods extends Controller
|
|
|
$LowPriceGoods = $LowPriceGoodsModel->where($where)->first();
|
|
$LowPriceGoods = $LowPriceGoodsModel->where($where)->first();
|
|
|
if (!$LowPriceGoods) return json_send(['code' => 'error', 'msg' => '违规记录不存在']);
|
|
if (!$LowPriceGoods) return json_send(['code' => 'error', 'msg' => '违规记录不存在']);
|
|
|
if ($LowPriceGoods->processing_status != '1') return json_send(['code' => 'error', 'msg' => '当前状态不是待处理,流程调用错误']);
|
|
if ($LowPriceGoods->processing_status != '1') return json_send(['code' => 'error', 'msg' => '当前状态不是待处理,流程调用错误']);
|
|
|
- if (!in_array($all_data['processing_status'],[7,8])) return json_send(['code' => 'error', 'msg' => '流程状态参数值错误']);
|
|
|
|
|
|
|
+ if (!in_array($all_data['processing_status'], [7, 8])) return json_send(['code' => 'error', 'msg' => '流程状态参数值错误']);
|
|
|
// 查询是否存在流程中的记录
|
|
// 查询是否存在流程中的记录
|
|
|
$map = ['lowprice_product_logid' => $id, 'processing_status' => $all_data['processing_status']];
|
|
$map = ['lowprice_product_logid' => $id, 'processing_status' => $all_data['processing_status']];
|
|
|
$record = $LowPriceGoodsRecordModel->where($map)->first();
|
|
$record = $LowPriceGoodsRecordModel->where($map)->first();
|
|
@@ -733,7 +735,7 @@ class LowPriceGoods extends Controller
|
|
|
$LowPriceGoods = $LowPriceGoodsModel->where($where)->first();
|
|
$LowPriceGoods = $LowPriceGoodsModel->where($where)->first();
|
|
|
if (!$LowPriceGoods) return json_send(['code' => 'error', 'msg' => '违规记录不存在']);
|
|
if (!$LowPriceGoods) return json_send(['code' => 'error', 'msg' => '违规记录不存在']);
|
|
|
if ($LowPriceGoods->processing_status != '2') return json_send(['code' => 'error', 'msg' => '当前状态不是购买中,流程调用错误']);
|
|
if ($LowPriceGoods->processing_status != '2') return json_send(['code' => 'error', 'msg' => '当前状态不是购买中,流程调用错误']);
|
|
|
- if ($all_data['processing_status'] != '3') return json_send(['code' => 'error', 'msg' => '流程状态参数值错误']);
|
|
|
|
|
|
|
+ if ($all_data['processing_status'] != '3') return json_send(['code' => 'error', 'msg' => '流程状态参数值错误']);
|
|
|
// 查询是否存在流程中的记录
|
|
// 查询是否存在流程中的记录
|
|
|
$map = ['lowprice_product_logid' => $id, 'processing_status' => $all_data['processing_status']];
|
|
$map = ['lowprice_product_logid' => $id, 'processing_status' => $all_data['processing_status']];
|
|
|
$record = $LowPriceGoodsRecordModel->where($map)->first();
|
|
$record = $LowPriceGoodsRecordModel->where($map)->first();
|
|
@@ -766,4 +768,197 @@ class LowPriceGoods extends Controller
|
|
|
return json_send(['code' => 'error', 'msg' => '流转失败', 'data' => $e->getMessage()]);
|
|
return json_send(['code' => 'error', 'msg' => '流转失败', 'data' => $e->getMessage()]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 下载导入模板
|
|
|
|
|
+ * @author 唐远望
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ * @date 2025-12-31
|
|
|
|
|
+ *
|
|
|
|
|
+ */
|
|
|
|
|
+ public function download_template()
|
|
|
|
|
+ {
|
|
|
|
|
+ // 创建一个新的 Spreadsheet 对象
|
|
|
|
|
+ $spreadsheet = new Spreadsheet();
|
|
|
|
|
+ $sheet = $spreadsheet->getActiveSheet();
|
|
|
|
|
+
|
|
|
|
|
+ //合并单元格
|
|
|
|
|
+ $sheet->mergeCells('A1:R1');
|
|
|
|
|
+ $sheet->setCellValue('A1', '低价挂网商品导入模板'); // 设置合并后的单元格内容
|
|
|
|
|
+ // 获取合并后的单元格样式对象
|
|
|
|
|
+ $style = $sheet->getStyle('A1');
|
|
|
|
|
+ // 设置水平居中和垂直居中
|
|
|
|
|
+ $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
|
|
|
|
|
+ // 然后设置行高以适应两行文本
|
|
|
|
|
+ $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
|
|
|
|
|
+ // 设置表头
|
|
|
|
|
+ $sheet->setCellValue('A2', '第一责任人');
|
|
|
|
|
+ $sheet->setCellValue('B2', '责任人');
|
|
|
|
|
+ $sheet->setCellValue('C2', '平台*');
|
|
|
|
|
+ $sheet->setCellValue('D2', '商品分类');
|
|
|
|
|
+ $sheet->setCellValue('E2', '商品名称*');
|
|
|
|
|
+ $sheet->setCellValue('F2', '商品规格*');
|
|
|
|
|
+ $sheet->setCellValue('G2', '指导价*');
|
|
|
|
|
+ $sheet->setCellValue('H2', '挂网价格*');
|
|
|
|
|
+ $sheet->setCellValue('I2', '累计挂网次数');
|
|
|
|
|
+ $sheet->setCellValue('J2', '连续挂网次数');
|
|
|
|
|
+ $sheet->setCellValue('K2', '链接地址*');
|
|
|
|
|
+ $sheet->setCellValue('L2', '店铺名称*');
|
|
|
|
|
+ $sheet->setCellValue('M2', '公司名称*');
|
|
|
|
|
+ $sheet->setCellValue('N2', '公司分类');
|
|
|
|
|
+ $sheet->setCellValue('O2', '信用代码*');
|
|
|
|
|
+ $sheet->setCellValue('P2', '省份*');
|
|
|
|
|
+ $sheet->setCellValue('Q2', '城市*');
|
|
|
|
|
+ $sheet->setCellValue('R2', '溯源责任人');
|
|
|
|
|
+ // 生成 Excel 文件
|
|
|
|
|
+ $writer = new Xlsx($spreadsheet);
|
|
|
|
|
+
|
|
|
|
|
+ // 直接输出到浏览器(下载)
|
|
|
|
|
+ $filename = '低价挂网商品导入模板.xlsx';
|
|
|
|
|
+ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
|
|
+ header('Content-Disposition: attachment;filename="' . $filename . '"');
|
|
|
|
|
+ header('Cache-Control: max-age=0');
|
|
|
|
|
+ $writer->save('php://output');
|
|
|
|
|
+ exit;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导入Excel数据
|
|
|
|
|
+ * @author 唐远望
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ * @date 2025-12-31
|
|
|
|
|
+ *
|
|
|
|
|
+ */
|
|
|
|
|
+ public function import_data(Request $request, LowPriceGoodsModel $LowPriceGoodsModel, EmployeeModel $EmployeeModel,CitysModel $CitysModel)
|
|
|
|
|
+ {
|
|
|
|
|
+ $request->scene('import_data')->validate();
|
|
|
|
|
+ $file = $request->file('file');
|
|
|
|
|
+ // 加载Excel文件
|
|
|
|
|
+ $spreadsheet = IOFactory::load($file->getPathname());
|
|
|
|
|
+ $sheet = $spreadsheet->getActiveSheet();
|
|
|
|
|
+ // 获取所有数据
|
|
|
|
|
+ $data = $sheet->toArray();
|
|
|
|
|
+ if (empty($data) || count($data) < 2) return json_send(['code' => 'error', 'msg' => '导入数据为空']);
|
|
|
|
|
+ $result = $EmployeeModel->select(['id', 'name'])->get()->keyBy('name')->toarray();
|
|
|
|
|
+ $platform_data = $LowPriceGoodsModel->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'];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $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[17];
|
|
|
|
|
+ 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[15];
|
|
|
|
|
+ if($province_name && !strpos($province_name,'省')){
|
|
|
|
|
+ if(!in_array($province_name,['北京','天津','上海','重庆'])){
|
|
|
|
|
+ $province_name = $province_name.'省';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $city_name = $item[16];
|
|
|
|
|
+ if($city_name && !strpos($city_name,'市')){
|
|
|
|
|
+ $city_name = $city_name.'市';
|
|
|
|
|
+ }
|
|
|
|
|
+ $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[3] : ''; // 商品分类
|
|
|
|
|
+ $insert_product_data['product_name'] = $item[4]; // 商品名称
|
|
|
|
|
+ $insert_product_data['product_specs'] = $item[5]; // 商品规格
|
|
|
|
|
+ $insert_product_data['suggested_price'] = $item[6]; // 指导价
|
|
|
|
|
+ $insert_product_data['online_posting_price'] = $item[7]; // 挂网价格
|
|
|
|
|
+ $insert_product_data['online_posting_count'] = isset($item[8]) ? $item[8] : 1; // 累计挂网次数
|
|
|
|
|
+ $insert_product_data['continuous_listing_count'] = isset($item[9]) ? $item[9] : 1; // 连续挂网次数
|
|
|
|
|
+ $insert_product_data['link_url'] = $item[10]; // 链接地址
|
|
|
|
|
+ $insert_product_data['store_name'] = $item[11]; // 店铺名称
|
|
|
|
|
+ $insert_product_data['company_name'] = $item[12]; // 公司名称
|
|
|
|
|
+ $insert_product_data['company_category_name'] = isset($item[13]) ? $item[13] : ''; // 公司分类
|
|
|
|
|
+ $insert_product_data['social_credit_code'] = $item[14]; // 信用代码
|
|
|
|
|
+ $insert_product_data['province_name'] = $item[15]; // 省份
|
|
|
|
|
+ $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[16]; // 城市
|
|
|
|
|
+ $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
|
|
|
|
|
+ //插入数据
|
|
|
|
|
+ $LowPriceGoodsModel->addLowPriceGoods($insert_product_data,true);
|
|
|
|
|
+ }
|
|
|
|
|
+ return json_send(['code' => 'success', 'msg' => '导入成功']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导入Excel数据必传参数校验
|
|
|
|
|
+ * @author 唐远望
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ * @date 2025-12-31
|
|
|
|
|
+ *
|
|
|
|
|
+ */
|
|
|
|
|
+ private function import_data_check($item)
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($item[2] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '平台不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item[4] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '商品名称不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item[5] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '商品规格不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item[6] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '指导价不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item[7] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '挂网价格不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item[10] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '链接地址不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item[11] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '店铺名称不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item[12] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '公司名称不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item[14] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '信用代码不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item[15] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '省份不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item[16] == '') {
|
|
|
|
|
+ return json_send(['code' => 'error', 'msg' => '城市不能为空']);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|