diff --git a/app/common/middleware/SignMiddleware.php b/app/common/middleware/SignMiddleware.php new file mode 100755 index 00000000..7a783ed4 --- /dev/null +++ b/app/common/middleware/SignMiddleware.php @@ -0,0 +1,84 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\middleware; + +use app\Request; +use crmeb\exceptions\AuthException; +use think\exception\ValidateException; +use think\Response; +use Throwable; + +class SignMiddleware extends BaseMiddleware +{ + + /** + * @param Request $request + * @throws Throwable + * @author xaboy + * @day 2020-04-10 + */ + public function before(Request $request) + { + try { + $appid = $request->header('appid'); + $timestamp = $request->header('timestamp'); + $sign = $request->header('sign'); + // 中台系统secret + $appSecret = 'St@tF!8r@fgjCu88fJB9eo4PTRHxsntC'; + $this->verifySign(['appid'=>$appid,'timestamp'=>$timestamp,'sign'=>$sign], $appSecret); + } catch (AuthException $e) { + $eArray = ($e->getResponse())->getData(); + throw new AuthException($eArray['message'] ?? '非法签名'); + return; + } catch (Throwable $e) { + throw new AuthException('非法请求'); + return; + } + } + + public function after(Response $response) + { + + } + + private function makeSign($data, $appSecret) + { + ksort($data); + $string = ""; + foreach ($data as $k => $v) { + if ($k == "sign" || is_array($v)) { + continue; + } + $string .= $k . "=" . $v . "&"; + } + $string = trim($string, "&"); + $string = $string . "&key=" . $appSecret; + $string = md5(md5($string)); + return strtolower($string); + } + + private function verifySign($data, $appSecret) + { + // 验证请求, 10秒钟失效 + if (time() - ($data['timestamp'] ?? 0) > 10) { + throw new AuthException('签名已失效'); + } + // 比对签名 + $clientSign = $data['sign'] ?? ''; + $serverSign = $this->makeSign($data, $appSecret); + if ($clientSign != $serverSign) { + throw new AuthException('签名校验失败'); + } + } +} \ No newline at end of file diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index c809b8d5..d1c0d087 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -239,7 +239,7 @@ class ProductRepository extends BaseRepository $result = $this->dao->create($product); $settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0, $data['mer_id']); - if(isset($data['mer_cate_id']) &&$data['mer_cate_id']!=0){ + if (isset($data['mer_cate_id']) && count($data['mer_cate_id']) != 0) { $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']); } $settleParams['attr'] = $this->setAttr($data['attr'], $result->product_id); @@ -277,7 +277,11 @@ class ProductRepository extends BaseRepository event('product.update.before', compact('id', 'data', 'merId', 'productType', 'conType')); $spuData = $product = $this->setProduct($data); $settleParams = $this->setAttrValue($data, $id, $productType, 1, $merId); - $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId); + if (isset($data['mer_cate_id']) && count($data['mer_cate_id']) != 0 ) { + if($data['mer_cate_id'][0]!=0){ + $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId); + } + } $settleParams['attr'] = $this->setAttr($data['attr'], $id); $content = [ 'content' => $conType ? json_encode($data['content']) : $data['content'], @@ -287,8 +291,8 @@ class ProductRepository extends BaseRepository $spuData['mer_id'] = $merId; $spuData['mer_labels'] = $data['mer_labels']; Db::startTrans(); - try{ - $res=$this->save($id, $settleParams, $content, $product, $productType); + try { + $res = $this->save($id, $settleParams, $content, $product, $productType); // if ($productType == 1) { //秒杀商品 // $dat = $this->setSeckillProduct($data); // app()->make(StoreSeckillActiveRepository::class)->updateByProduct($id, $dat); @@ -303,10 +307,10 @@ class ProductRepository extends BaseRepository if ($data['status'] == 0) { event('product.sell', ['product_id' => [$id]]); } - app()->make(SpuRepository::class)->changeStatus($id, $productType); - Db::commit(); - return $res; - }catch(\Exception $e){ + app()->make(SpuRepository::class)->changeStatus($id, $productType); + Db::commit(); + return $res; + } catch (\Exception $e) { Db::rollback(); return false; } @@ -525,7 +529,7 @@ class ProductRepository extends BaseRepository { $result = []; foreach ($data as $value) { - if($value['category']){ + if ($value['category']) { $result[] = [ 'product_id' => $productId, 'mer_cate_id' => $value, @@ -790,7 +794,7 @@ class ProductRepository extends BaseRepository unset($data['content']); $data['content'] = $content; // $attr = $this->detailAttr($data['attr']); - $attrValue =$data['attrValue']; + $attrValue = $data['attrValue']; $sku = $this->detailAttrValue($attrValue, null, $data['product_type'], null); $data['sku'] = $sku; @@ -842,7 +846,7 @@ class ProductRepository extends BaseRepository $where['product_type'] = $productType; if (!$merId) $where['is_gift_bag'] = 0; } - if ($productType == 1 ||$productType==98) { + if ($productType == 1 || $productType == 98) { $where['product_type'] = $productType; } if ($productType == 10) { @@ -988,6 +992,7 @@ class ProductRepository extends BaseRepository 'storeCategory', 'brand', 'merchant', + 'attrValue' ]); $count = $query->count(); $data = $query->page($page, $limit)->setOption('field', [])->field($this->admin_filed)->select(); @@ -2355,8 +2360,8 @@ class ProductRepository extends BaseRepository $stockIn = $params['number'] ?? 0; $price = $params['price'] ?? 0; $orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id']) - ->where('product_sku', $params['order_unique'])->find(); - $stockIn=$orderProduct['product_num']; + ->where('product_sku', $params['order_unique'])->find(); + $stockIn = $orderProduct['product_num']; if ($stockIn <= 0) { throw new ValidateException('入库数量不能小于等于0'); } @@ -2376,7 +2381,7 @@ class ProductRepository extends BaseRepository } if ($orderProduct->is_imported == 0) { - $attrValue->stock=$attrValue->stock + $stockIn; + $attrValue->stock = $attrValue->stock + $stockIn; $product->stock = $stockIn + $product->stock; $data = [ 'order_id' => $params['order_id'] ?? 0, @@ -2397,7 +2402,7 @@ class ProductRepository extends BaseRepository $product->save(); Db::commit(); return true; - }else{ + } else { throw new ValidateException('该商品已导入过'); } $stockIn = $orderProduct['product_num'] ?? 0; diff --git a/app/controller/middle/Merchant.php b/app/controller/middle/Merchant.php new file mode 100644 index 00000000..0e8c665f --- /dev/null +++ b/app/controller/middle/Merchant.php @@ -0,0 +1,45 @@ +repository = $repository; + } + + public function get_area(){ + $city_code = $this->request->param('city_code', ''); + $select = Db::name('geo_area')->where('city_code',$city_code)->field('area_id id,area_code code,area_name name')->select(); + return app('json')->success($select); + } + + public function count() + { + $where = $this->request->params(['keyword', 'date', 'status', 'statusTag', 'is_trader', 'category_id', 'type_id']); + return app('json')->success($this->repository->count($where)); + } + + public function lst() + { + [$page, $limit] = $this->getPage(); + $where = $this->request->params(['keyword', 'date', 'status', 'statusTag', 'is_trader', 'category_id', 'type_id', 'area_id', 'street_id']); + return app('json')->success($this->repository->lst($where, $page, $limit)); + } + +} diff --git a/app/controller/middle/MerchantCategory.php b/app/controller/middle/MerchantCategory.php new file mode 100644 index 00000000..b915faf9 --- /dev/null +++ b/app/controller/middle/MerchantCategory.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + public function getOptions() + { + return app('json')->success($this->repository->allOptions()); + } + +} diff --git a/app/controller/middle/MerchantType.php b/app/controller/middle/MerchantType.php new file mode 100644 index 00000000..72f5f51b --- /dev/null +++ b/app/controller/middle/MerchantType.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + public function options() + { + return app('json')->success($this->repository->getOptions()); + } + +} diff --git a/app/controller/middle/ProductLabel.php b/app/controller/middle/ProductLabel.php new file mode 100644 index 00000000..0bd62384 --- /dev/null +++ b/app/controller/middle/ProductLabel.php @@ -0,0 +1,32 @@ +repository = $repository; + } + + public function getOptions() + { + $data = $this->repository->getOptions(0); + return app('json')->success($data); + } + + +} diff --git a/app/controller/middle/StoreCategory.php b/app/controller/middle/StoreCategory.php new file mode 100644 index 00000000..99149f71 --- /dev/null +++ b/app/controller/middle/StoreCategory.php @@ -0,0 +1,35 @@ +repository = $repository; + } + + public function getList() + { + $type = $this->request->param('type',null); + $lv = $this->request->param('lv',null); + if (!is_null($lv)) $lv = $lv + 1; + $data = $this->repository->getList($type, $lv); + return app('json')->success($data); + } + + +} diff --git a/app/controller/middle/StoreProduct.php b/app/controller/middle/StoreProduct.php new file mode 100644 index 00000000..e41713c3 --- /dev/null +++ b/app/controller/middle/StoreProduct.php @@ -0,0 +1,52 @@ +repository = $repository; + } + + public function getStatusFilter() + { + return app('json')->success($this->repository->getFilter(null,'商品',0)); + } + + public function lst() + { + [$page, $limit] = $this->getPage(); + $where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'pid','store_name','is_trader','us_status','product_id','star','sys_labels','hot_type','svip_price_type']); + $mer_id = $this->request->param('mer_id',''); + $merId = $mer_id ? $mer_id : null; + $where['is_gift_bag'] = 0; + $_where = $this->repository->switchType($where['type'], null,0); + unset($_where['product_type']); + unset($_where['star']); + $where = array_merge($where, $_where); + return app('json')->success($this->repository->getAdminList($merId, $where, $page, $limit)); + } + + public function lists() + { + $make = app()->make(MerchantRepository::class); + $data = $make->selectWhere(['is_del' => 0],'mer_id,mer_name'); + return app('json')->success($data); + } + +} diff --git a/app/controller/middle/User.php b/app/controller/middle/User.php new file mode 100644 index 00000000..5b0eee33 --- /dev/null +++ b/app/controller/middle/User.php @@ -0,0 +1,47 @@ +repository = $repository; + } + + public function lst() + { + $where = $this->request->params([ + 'label_id', + 'user_type', + 'sex', + 'is_promoter', + 'country', + 'pay_count', + 'user_time_type', + 'user_time', + 'nickname', + 'province', + 'city', + 'group_id', + 'phone', + 'uid', + ]); + [$page, $limit] = $this->getPage(); + return app('json')->success($this->repository->getList($where, $page, $limit)); + } + +} diff --git a/app/controller/middle/UserGroup.php b/app/controller/middle/UserGroup.php new file mode 100644 index 00000000..b433b740 --- /dev/null +++ b/app/controller/middle/UserGroup.php @@ -0,0 +1,32 @@ +repository = $repository; + } + + public function lst() + { + $page = 1; + $limit = 9999; + return app('json')->success($this->repository->getList([], $page, $limit)); + } + +} diff --git a/app/controller/middle/UserLabel.php b/app/controller/middle/UserLabel.php new file mode 100644 index 00000000..06bfe7f1 --- /dev/null +++ b/app/controller/middle/UserLabel.php @@ -0,0 +1,34 @@ +repository = $repository; + } + + public function lst() + { + $page = 1; + $limit = 9999; + $where = $this->request->params(['type', 'all']); + $where['mer_id'] = $this->request->merId(); + return app('json')->success($this->repository->getList($where, $page, $limit)); + } + +} diff --git a/crmeb/services/SpreadsheetExcelService.php b/crmeb/services/SpreadsheetExcelService.php index f454ddb8..ae8e4636 100644 --- a/crmeb/services/SpreadsheetExcelService.php +++ b/crmeb/services/SpreadsheetExcelService.php @@ -44,19 +44,19 @@ class SpreadsheetExcelService protected static $colum = 3; //设置style private static $styleArray = [ -// 'borders' => [ -// 'allBorders' => [ -// // PHPExcel_Style_Border里面有很多属性,想要其他的自己去看 -// // 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,//边框是粗的 -// // 'style' => \PHPExcel_Style_Border::BORDER_DOUBLE,//双重的 -// // 'style' => \PHPExcel_Style_Border::BORDER_HAIR,//虚线 -// // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUM,//实粗线 -// // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT,//虚粗线 -// // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT,//点虚粗线 -// 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,//细边框 -// // 'color' => ['argb' => 'FFFF0000'], -// ], -// ], + // 'borders' => [ + // 'allBorders' => [ + // // PHPExcel_Style_Border里面有很多属性,想要其他的自己去看 + // // 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,//边框是粗的 + // // 'style' => \PHPExcel_Style_Border::BORDER_DOUBLE,//双重的 + // // 'style' => \PHPExcel_Style_Border::BORDER_HAIR,//虚线 + // // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUM,//实粗线 + // // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT,//虚粗线 + // // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT,//点虚粗线 + // 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,//细边框 + // // 'color' => ['argb' => 'FFFF0000'], + // ], + // ], 'font' => [ 'bold' => true ], @@ -66,9 +66,13 @@ class SpreadsheetExcelService ] ]; - private function __construct(){} + private function __construct() + { + } - private function __clone(){} + private function __clone() + { + } public static function instance() { @@ -81,9 +85,9 @@ class SpreadsheetExcelService public function createOrActive($i = null) { - if($i){ + if ($i) { self::$sheet = self::$spreadsheet->createSheet(); - }else{ + } else { self::$sheet = self::$spreadsheet->getActiveSheet(); } return $this; @@ -104,21 +108,21 @@ class SpreadsheetExcelService */ public static function savePath() { - if(!is_dir(self::$path)){ + if (!is_dir(self::$path)) { if (mkdir(self::$path, 0700) == false) { return false; } } //年月一级目录 - $mont_path = self::$path.date('Ym'); - if(!is_dir($mont_path)){ + $mont_path = self::$path . date('Ym'); + if (!is_dir($mont_path)) { if (mkdir($mont_path, 0700) == false) { return false; } } //日二级目录 - $day_path = $mont_path.'/'.date('d'); - if(!is_dir($day_path)){ + $day_path = $mont_path . '/' . date('d'); + if (!is_dir($day_path)) { if (mkdir($day_path, 0700) == false) { return false; } @@ -163,16 +167,16 @@ class SpreadsheetExcelService self::$sheet->getStyle('A1')->getFont()->setBold(true); self::$sheet->getStyle('A1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); //设置左对齐 - if(isset($data['mark']) && !empty($data['mark'])){ - foreach ($data['mark'] as $k => $v){ + if (isset($data['mark']) && !empty($data['mark'])) { + foreach ($data['mark'] as $k => $v) { $i = $k + 2; - self::$sheet->mergeCells('A'.$i.':' . self::$cells . $i); - self::$sheet->setCellValue('A'.$i, $v); + self::$sheet->mergeCells('A' . $i . ':' . self::$cells . $i); + self::$sheet->setCellValue('A' . $i, $v); - self::$sheet->getStyle('A'.$i)->getFont()->setName('宋体'); - self::$sheet->getStyle('A'.$i)->getFont()->setSize(16); - self::$sheet->getStyle('A'.$i)->getFont()->setBold(true); - self::$sheet->getStyle('A'.$i)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT); + self::$sheet->getStyle('A' . $i)->getFont()->setName('宋体'); + self::$sheet->getStyle('A' . $i)->getFont()->setSize(16); + self::$sheet->getStyle('A' . $i)->getFont()->setBold(true); + self::$sheet->getStyle('A' . $i)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT); } } @@ -213,19 +217,19 @@ class SpreadsheetExcelService * @param $data array * @return $this */ - public function setExcelHeader($data,$topNumber) + public function setExcelHeader($data, $topNumber) { $span = 'A'; self::$topNumber = $topNumber; foreach ($data as $key => $value) { self::$sheet->getColumnDimension($span)->setWidth(self::$width); - self::$sheet->setCellValue($span.self::$topNumber, $value); - self::$sheet->getStyle($span.self::$topNumber)->getFont()->setSize(16); + self::$sheet->setCellValue($span . self::$topNumber, $value); + self::$sheet->getStyle($span . self::$topNumber)->getFont()->setSize(16); $span++; } - $span = chr(ord($span) -1); + $span = chr(ord($span) - 1); self::$sheet->getRowDimension(self::$topNumber)->setRowHeight(25); - self::$sheet->getStyle('A1:' . $span.self::$topNumber)->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN); + self::$sheet->getStyle('A1:' . $span . self::$topNumber)->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN); self::$cells = $span; return $this; @@ -241,7 +245,7 @@ class SpreadsheetExcelService public function setExcelContent($data = []) { if (!empty($data) && is_array($data)) { - $column = self::$topNumber+1; + $column = self::$topNumber + 1; // 行写入 foreach ($data as $key => $rows) { $span = 'A'; @@ -252,33 +256,33 @@ class SpreadsheetExcelService } $column++; } - $span = chr(ord($span) -1); + $span = chr(ord($span) - 1); self::$colum = $column; self::$sheet->getDefaultRowDimension()->setRowHeight(self::$height); //设置内容字体样式 - self::$sheet->getStyle('A'.self::$topNumber .':'. $span.$column)->applyFromArray(self::$styleArray); + self::$sheet->getStyle('A' . self::$topNumber . ':' . $span . $column)->applyFromArray(self::$styleArray); //设置边框 - self::$sheet->getStyle('A1:' . $span.$column )->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN); + self::$sheet->getStyle('A1:' . $span . $column)->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN); //设置自动换行 - self::$sheet->getStyle('A4:' . $span.$column)->getAlignment()->setWrapText(true); + self::$sheet->getStyle('A4:' . $span . $column)->getAlignment()->setWrapText(true); } return $this; } public function setExcelEnd(array $data) { - if(!empty($data)){ - foreach ($data as $key => $value){ - $i = self::$colum + $key ; - self::$sheet->mergeCells('A'.$i.':' . self::$cells.$i); - self::$sheet->setCellValue('A'.$i, $value); + if (!empty($data)) { + foreach ($data as $key => $value) { + $i = self::$colum + $key; + self::$sheet->mergeCells('A' . $i . ':' . self::$cells . $i); + self::$sheet->setCellValue('A' . $i, $value); - self::$sheet->getStyle('A'.$i)->getFont()->setName('宋体'); - self::$sheet->getStyle('A'.$i)->getFont()->setSize(16); - self::$sheet->getStyle('A'.$i)->getFont()->setBold(true); - self::$sheet->getStyle('A'.$i)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT); + self::$sheet->getStyle('A' . $i)->getFont()->setName('宋体'); + self::$sheet->getStyle('A' . $i)->getFont()->setSize(16); + self::$sheet->getStyle('A' . $i)->getFont()->setBold(true); + self::$sheet->getStyle('A' . $i)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT); } - self::$sheet->getStyle('A1:' .self::$cells.$i)->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN); + self::$sheet->getStyle('A1:' . self::$cells . $i)->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN); } return $this; } @@ -291,21 +295,21 @@ class SpreadsheetExcelService * @param $path 是否保存文件文件 * @return 保存文件:return string */ - public function excelSave($fileName = '',$suffix = 'xlsx',$path) + public function excelSave($fileName = '', $suffix = 'xlsx', $path) { - if(empty($fileName)) $fileName = date('YmdHis').time(); - if(empty($suffix)) $suffix = 'xlsx'; + if (empty($fileName)) $fileName = date('YmdHis') . time(); + if (empty($suffix)) $suffix = 'xlsx'; // 重命名表(UTF8编码不需要这一步) if (mb_detect_encoding($fileName) != "UTF-8") $fileName = iconv("utf-8", "gbk//IGNORE", $fileName); - $save_path = self::$path.$path; - $root_path = app()->getRootPath().'public/'.$save_path; - if(!is_dir($root_path)) mkdir($root_path, 0755,true); + $save_path = self::$path . $path; + $root_path = app()->getRootPath() . 'public/' . $save_path; + if (!is_dir($root_path)) mkdir($root_path, 0755, true); $spreadsheet = self::$spreadsheet; $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet); - $writer->save($root_path.'/'.$fileName.'.'.$suffix); + $writer->save($root_path . '/' . $fileName . '.' . $suffix); - return $save_path.'/'.$fileName.'.'.$suffix; + return $save_path . '/' . $fileName . '.' . $suffix; } /** @@ -318,9 +322,9 @@ class SpreadsheetExcelService * @author Qinii * @day 3/15/21 */ - public function _import($filePath,array $sql,$where = [],$startRow = 1) + public function _import($filePath, array $sql, $where = [], $startRow = 1) { - if(!file_exists($filePath)) return ; + if (!file_exists($filePath)) return; $ext = ucfirst(pathinfo($filePath, PATHINFO_EXTENSION)); $ret = []; if (in_array($ext, ['Xlsx', 'Xls'])) { @@ -328,16 +332,16 @@ class SpreadsheetExcelService $reader->setReadDataOnly(true); $spreadsheet = $reader->load($filePath); $sheet = $spreadsheet->getActiveSheet(); - $row_count = $sheet->getHighestDataRow();//取得总行数 + $row_count = $sheet->getHighestDataRow(); //取得总行数 for ($row = $startRow; $row <= $row_count; $row++) { $con = []; $item = []; $one = []; -// $getK = $sheet->getCell('A'.$row)->getValue(); -// if ($getK) { -// $getV = $sheet->getCell('B'.$row)->getValue(); -// $one[] = [$getK => $getV]; -// } + // $getK = $sheet->getCell('A'.$row)->getValue(); + // if ($getK) { + // $getV = $sheet->getCell('B'.$row)->getValue(); + // $one[] = [$getK => $getV]; + // } if (!empty($where)) { foreach ($where as $k => $v) { $con_value = $sheet->getCell($v . $row)->getValue(); @@ -369,26 +373,29 @@ class SpreadsheetExcelService * @author Qinii * @day 5/7/21 */ - public function checkImport($filePath,$check = [],$is_limit=false,$count=1000) + public function checkImport($filePath, $check = [], $is_limit = false, $count = 1000) { - $ext = ucfirst(pathinfo($filePath, PATHINFO_EXTENSION)); - $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($ext); - $spreadsheet = $reader->load($filePath); - $sheet = $spreadsheet->getActiveSheet(); - if($is_limit==true){ - $limit=$sheet->getHighestRow(); - if($limit>$count){ - throw new ValidateException('导入的条数超过限制数量:'.$count.',当前表格数量'.$limit); + try { + $ext = ucfirst(pathinfo($filePath, PATHINFO_EXTENSION)); + $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($ext); + $spreadsheet = $reader->load($filePath); + $sheet = $spreadsheet->getActiveSheet(); + if ($is_limit == true) { + $limit = $sheet->getHighestRow(); + if ($limit > $count) { + throw new ValidateException('导入的条数超过限制数量:' . $count . ',当前表格数量' . $limit); + } } - } - if(!empty($check)){ - foreach ($check as $s => $c){ - $_c = $sheet->getCell($s)->getValue(); - if($_c !== $c) throw new ValidateException('表格"'.$s.'"不是"'.$c.'"不可导入'); + if (!empty($check)) { + foreach ($check as $s => $c) { + $_c = $sheet->getCell($s)->getValue(); + if ($_c !== $c) throw new ValidateException('表格"' . $s . '"不是"' . $c . '"不可导入'); + } } + } catch (\Exception $e) { + throw new ValidateException('表格中有无法解析的编码,请重新设置表格'); } return true; } - } diff --git a/route/middle.php b/route/middle.php new file mode 100755 index 00000000..5eff9653 --- /dev/null +++ b/route/middle.php @@ -0,0 +1,33 @@ + +// +---------------------------------------------------------------------- + +use app\common\middleware\SignMiddleware; +use think\facade\Route; + +Route::group('middle/', function () { + Route::any('product/label/option', 'middle.ProductLabel/getOptions'); + Route::any('store/product/lst_filter', 'middle.StoreProduct/getStatusFilter'); + Route::any('store/product/lst', 'middle.StoreProduct/lst'); + Route::any('store/product/mer_select', 'middle.StoreProduct/lists'); + Route::any('store/category/list', 'middle.StoreCategory/getList'); + + Route::any('user/group/lst', 'middle.UserGroup/lst'); + Route::any('user/label/lst', 'middle.UserLabel/lst'); + Route::any('user/lst', 'middle.User/lst'); + + Route::any('merchant/city/get_area', 'middle.Merchant/get_area'); + Route::any('merchant/count', 'middle.Merchant/count'); + Route::any('merchant/category/options', 'middle.MerchantCategory/getOptions'); + Route::any('merchant/type/options', 'middle.MerchantType/options'); + Route::any('merchant/lst', 'middle.Merchant/lst'); + +})->middleware(SignMiddleware::class); \ No newline at end of file