Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
chenbo 2023-12-04 16:01:23 +08:00
commit 0cb8a70d1a
13 changed files with 564 additions and 96 deletions

View File

@ -0,0 +1,84 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
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('签名校验失败');
}
}
}

View File

@ -239,7 +239,7 @@ class ProductRepository extends BaseRepository
$result = $this->dao->create($product); $result = $this->dao->create($product);
$settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0, $data['mer_id']); $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['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']);
} }
$settleParams['attr'] = $this->setAttr($data['attr'], $result->product_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')); event('product.update.before', compact('id', 'data', 'merId', 'productType', 'conType'));
$spuData = $product = $this->setProduct($data); $spuData = $product = $this->setProduct($data);
$settleParams = $this->setAttrValue($data, $id, $productType, 1, $merId); $settleParams = $this->setAttrValue($data, $id, $productType, 1, $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['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId);
}
}
$settleParams['attr'] = $this->setAttr($data['attr'], $id); $settleParams['attr'] = $this->setAttr($data['attr'], $id);
$content = [ $content = [
'content' => $conType ? json_encode($data['content']) : $data['content'], 'content' => $conType ? json_encode($data['content']) : $data['content'],
@ -287,8 +291,8 @@ class ProductRepository extends BaseRepository
$spuData['mer_id'] = $merId; $spuData['mer_id'] = $merId;
$spuData['mer_labels'] = $data['mer_labels']; $spuData['mer_labels'] = $data['mer_labels'];
Db::startTrans(); Db::startTrans();
try{ try {
$res=$this->save($id, $settleParams, $content, $product, $productType); $res = $this->save($id, $settleParams, $content, $product, $productType);
// if ($productType == 1) { //秒杀商品 // if ($productType == 1) { //秒杀商品
// $dat = $this->setSeckillProduct($data); // $dat = $this->setSeckillProduct($data);
// app()->make(StoreSeckillActiveRepository::class)->updateByProduct($id, $dat); // app()->make(StoreSeckillActiveRepository::class)->updateByProduct($id, $dat);
@ -306,7 +310,7 @@ class ProductRepository extends BaseRepository
app()->make(SpuRepository::class)->changeStatus($id, $productType); app()->make(SpuRepository::class)->changeStatus($id, $productType);
Db::commit(); Db::commit();
return $res; return $res;
}catch(\Exception $e){ } catch (\Exception $e) {
Db::rollback(); Db::rollback();
return false; return false;
} }
@ -525,7 +529,7 @@ class ProductRepository extends BaseRepository
{ {
$result = []; $result = [];
foreach ($data as $value) { foreach ($data as $value) {
if($value['category']){ if ($value['category']) {
$result[] = [ $result[] = [
'product_id' => $productId, 'product_id' => $productId,
'mer_cate_id' => $value, 'mer_cate_id' => $value,
@ -790,7 +794,7 @@ class ProductRepository extends BaseRepository
unset($data['content']); unset($data['content']);
$data['content'] = $content; $data['content'] = $content;
// $attr = $this->detailAttr($data['attr']); // $attr = $this->detailAttr($data['attr']);
$attrValue =$data['attrValue']; $attrValue = $data['attrValue'];
$sku = $this->detailAttrValue($attrValue, null, $data['product_type'], null); $sku = $this->detailAttrValue($attrValue, null, $data['product_type'], null);
$data['sku'] = $sku; $data['sku'] = $sku;
@ -842,7 +846,7 @@ class ProductRepository extends BaseRepository
$where['product_type'] = $productType; $where['product_type'] = $productType;
if (!$merId) $where['is_gift_bag'] = 0; if (!$merId) $where['is_gift_bag'] = 0;
} }
if ($productType == 1 ||$productType==98) { if ($productType == 1 || $productType == 98) {
$where['product_type'] = $productType; $where['product_type'] = $productType;
} }
if ($productType == 10) { if ($productType == 10) {
@ -988,6 +992,7 @@ class ProductRepository extends BaseRepository
'storeCategory', 'storeCategory',
'brand', 'brand',
'merchant', 'merchant',
'attrValue'
]); ]);
$count = $query->count(); $count = $query->count();
$data = $query->page($page, $limit)->setOption('field', [])->field($this->admin_filed)->select(); $data = $query->page($page, $limit)->setOption('field', [])->field($this->admin_filed)->select();
@ -2356,7 +2361,7 @@ class ProductRepository extends BaseRepository
$price = $params['price'] ?? 0; $price = $params['price'] ?? 0;
$orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id']) $orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])
->where('product_sku', $params['order_unique'])->find(); ->where('product_sku', $params['order_unique'])->find();
$stockIn=$orderProduct['product_num']; $stockIn = $orderProduct['product_num'];
if ($stockIn <= 0) { if ($stockIn <= 0) {
throw new ValidateException('入库数量不能小于等于0'); throw new ValidateException('入库数量不能小于等于0');
} }
@ -2376,7 +2381,7 @@ class ProductRepository extends BaseRepository
} }
if ($orderProduct->is_imported == 0) { if ($orderProduct->is_imported == 0) {
$attrValue->stock=$attrValue->stock + $stockIn; $attrValue->stock = $attrValue->stock + $stockIn;
$product->stock = $stockIn + $product->stock; $product->stock = $stockIn + $product->stock;
$data = [ $data = [
'order_id' => $params['order_id'] ?? 0, 'order_id' => $params['order_id'] ?? 0,
@ -2397,7 +2402,7 @@ class ProductRepository extends BaseRepository
$product->save(); $product->save();
Db::commit(); Db::commit();
return true; return true;
}else{ } else {
throw new ValidateException('该商品已导入过'); throw new ValidateException('该商品已导入过');
} }
$stockIn = $orderProduct['product_num'] ?? 0; $stockIn = $orderProduct['product_num'] ?? 0;

View File

@ -0,0 +1,45 @@
<?php
namespace app\controller\middle;
use crmeb\basic\BaseController;
use think\App;
use think\facade\Db;
use app\common\repositories\system\merchant\MerchantRepository;
/**
* Class Auth
* @package app\controller\api
* @author xaboy
* @day 2020-05-06
*/
class Merchant extends BaseController
{
protected $repository;
public function __construct(App $app, MerchantRepository $repository)
{
parent::__construct($app);
$this->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));
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace app\controller\middle;
use crmeb\basic\BaseController;
use think\App;
use think\facade\Db;
use app\common\repositories\system\merchant\MerchantCategoryRepository;
/**
* Class Auth
* @package app\controller\api
* @author xaboy
* @day 2020-05-06
*/
class MerchantCategory extends BaseController
{
protected $repository;
public function __construct(App $app, MerchantCategoryRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function getOptions()
{
return app('json')->success($this->repository->allOptions());
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace app\controller\middle;
use crmeb\basic\BaseController;
use think\App;
use think\facade\Db;
use app\common\repositories\system\merchant\MerchantTypeRepository;
/**
* Class Auth
* @package app\controller\api
* @author xaboy
* @day 2020-05-06
*/
class MerchantType extends BaseController
{
protected $repository;
public function __construct(App $app, MerchantTypeRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function options()
{
return app('json')->success($this->repository->getOptions());
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace app\controller\middle;
use crmeb\basic\BaseController;
use think\App;
use app\common\repositories\store\product\ProductLabelRepository;
/**
* Class Auth
* @package app\controller\api
* @author xaboy
* @day 2020-05-06
*/
class ProductLabel extends BaseController
{
protected $repository;
public function __construct(App $app, ProductLabelRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function getOptions()
{
$data = $this->repository->getOptions(0);
return app('json')->success($data);
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\controller\middle;
use crmeb\basic\BaseController;
use think\App;
use app\common\repositories\store\StoreCategoryRepository;
/**
* Class Auth
* @package app\controller\api
* @author xaboy
* @day 2020-05-06
*/
class StoreCategory extends BaseController
{
protected $repository;
public function __construct(App $app, StoreCategoryRepository $repository)
{
parent::__construct($app);
$this->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);
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace app\controller\middle;
use crmeb\basic\BaseController;
use think\App;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\system\merchant\MerchantRepository;
/**
* Class Auth
* @package app\controller\api
* @author xaboy
* @day 2020-05-06
*/
class StoreProduct extends BaseController
{
protected $repository;
public function __construct(App $app, ProductRepository $repository)
{
parent::__construct($app);
$this->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);
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace app\controller\middle;
use crmeb\basic\BaseController;
use think\App;
use app\common\repositories\user\UserRepository;
/**
* Class Auth
* @package app\controller\api
* @author xaboy
* @day 2020-05-06
*/
class User extends BaseController
{
protected $repository;
public function __construct(App $app, UserRepository $repository)
{
parent::__construct($app);
$this->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));
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace app\controller\middle;
use crmeb\basic\BaseController;
use think\App;
use app\common\repositories\user\UserGroupRepository;
/**
* Class Auth
* @package app\controller\api
* @author xaboy
* @day 2020-05-06
*/
class UserGroup extends BaseController
{
protected $repository;
public function __construct(App $app, UserGroupRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function lst()
{
$page = 1;
$limit = 9999;
return app('json')->success($this->repository->getList([], $page, $limit));
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace app\controller\middle;
use crmeb\basic\BaseController;
use think\App;
use app\common\repositories\user\UserLabelRepository;
/**
* Class Auth
* @package app\controller\api
* @author xaboy
* @day 2020-05-06
*/
class UserLabel extends BaseController
{
protected $repository;
public function __construct(App $app, UserLabelRepository $repository)
{
parent::__construct($app);
$this->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));
}
}

View File

@ -44,19 +44,19 @@ class SpreadsheetExcelService
protected static $colum = 3; protected static $colum = 3;
//设置style //设置style
private static $styleArray = [ private static $styleArray = [
// 'borders' => [ // 'borders' => [
// 'allBorders' => [ // 'allBorders' => [
// // PHPExcel_Style_Border里面有很多属性想要其他的自己去看 // // PHPExcel_Style_Border里面有很多属性想要其他的自己去看
// // 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,//边框是粗的 // // 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,//边框是粗的
// // 'style' => \PHPExcel_Style_Border::BORDER_DOUBLE,//双重的 // // 'style' => \PHPExcel_Style_Border::BORDER_DOUBLE,//双重的
// // 'style' => \PHPExcel_Style_Border::BORDER_HAIR,//虚线 // // 'style' => \PHPExcel_Style_Border::BORDER_HAIR,//虚线
// // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUM,//实粗线 // // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUM,//实粗线
// // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT,//虚粗线 // // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT,//虚粗线
// // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT,//点虚粗线 // // 'style' => \PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT,//点虚粗线
// 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,//细边框 // 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,//细边框
// // 'color' => ['argb' => 'FFFF0000'], // // 'color' => ['argb' => 'FFFF0000'],
// ], // ],
// ], // ],
'font' => [ 'font' => [
'bold' => true 'bold' => true
], ],
@ -66,9 +66,13 @@ class SpreadsheetExcelService
] ]
]; ];
private function __construct(){} private function __construct()
{
}
private function __clone(){} private function __clone()
{
}
public static function instance() public static function instance()
{ {
@ -81,9 +85,9 @@ class SpreadsheetExcelService
public function createOrActive($i = null) public function createOrActive($i = null)
{ {
if($i){ if ($i) {
self::$sheet = self::$spreadsheet->createSheet(); self::$sheet = self::$spreadsheet->createSheet();
}else{ } else {
self::$sheet = self::$spreadsheet->getActiveSheet(); self::$sheet = self::$spreadsheet->getActiveSheet();
} }
return $this; return $this;
@ -104,21 +108,21 @@ class SpreadsheetExcelService
*/ */
public static function savePath() public static function savePath()
{ {
if(!is_dir(self::$path)){ if (!is_dir(self::$path)) {
if (mkdir(self::$path, 0700) == false) { if (mkdir(self::$path, 0700) == false) {
return false; return false;
} }
} }
//年月一级目录 //年月一级目录
$mont_path = self::$path.date('Ym'); $mont_path = self::$path . date('Ym');
if(!is_dir($mont_path)){ if (!is_dir($mont_path)) {
if (mkdir($mont_path, 0700) == false) { if (mkdir($mont_path, 0700) == false) {
return false; return false;
} }
} }
//日二级目录 //日二级目录
$day_path = $mont_path.'/'.date('d'); $day_path = $mont_path . '/' . date('d');
if(!is_dir($day_path)){ if (!is_dir($day_path)) {
if (mkdir($day_path, 0700) == false) { if (mkdir($day_path, 0700) == false) {
return false; return false;
} }
@ -163,16 +167,16 @@ class SpreadsheetExcelService
self::$sheet->getStyle('A1')->getFont()->setBold(true); self::$sheet->getStyle('A1')->getFont()->setBold(true);
self::$sheet->getStyle('A1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); //设置左对齐 self::$sheet->getStyle('A1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); //设置左对齐
if(isset($data['mark']) && !empty($data['mark'])){ if (isset($data['mark']) && !empty($data['mark'])) {
foreach ($data['mark'] as $k => $v){ foreach ($data['mark'] as $k => $v) {
$i = $k + 2; $i = $k + 2;
self::$sheet->mergeCells('A'.$i.':' . self::$cells . $i); self::$sheet->mergeCells('A' . $i . ':' . self::$cells . $i);
self::$sheet->setCellValue('A'.$i, $v); self::$sheet->setCellValue('A' . $i, $v);
self::$sheet->getStyle('A'.$i)->getFont()->setName('宋体'); self::$sheet->getStyle('A' . $i)->getFont()->setName('宋体');
self::$sheet->getStyle('A'.$i)->getFont()->setSize(16); self::$sheet->getStyle('A' . $i)->getFont()->setSize(16);
self::$sheet->getStyle('A'.$i)->getFont()->setBold(true); 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)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT);
} }
} }
@ -213,19 +217,19 @@ class SpreadsheetExcelService
* @param $data array * @param $data array
* @return $this * @return $this
*/ */
public function setExcelHeader($data,$topNumber) public function setExcelHeader($data, $topNumber)
{ {
$span = 'A'; $span = 'A';
self::$topNumber = $topNumber; self::$topNumber = $topNumber;
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
self::$sheet->getColumnDimension($span)->setWidth(self::$width); self::$sheet->getColumnDimension($span)->setWidth(self::$width);
self::$sheet->setCellValue($span.self::$topNumber, $value); self::$sheet->setCellValue($span . self::$topNumber, $value);
self::$sheet->getStyle($span.self::$topNumber)->getFont()->setSize(16); self::$sheet->getStyle($span . self::$topNumber)->getFont()->setSize(16);
$span++; $span++;
} }
$span = chr(ord($span) -1); $span = chr(ord($span) - 1);
self::$sheet->getRowDimension(self::$topNumber)->setRowHeight(25); 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; self::$cells = $span;
return $this; return $this;
@ -241,7 +245,7 @@ class SpreadsheetExcelService
public function setExcelContent($data = []) public function setExcelContent($data = [])
{ {
if (!empty($data) && is_array($data)) { if (!empty($data) && is_array($data)) {
$column = self::$topNumber+1; $column = self::$topNumber + 1;
// 行写入 // 行写入
foreach ($data as $key => $rows) { foreach ($data as $key => $rows) {
$span = 'A'; $span = 'A';
@ -252,33 +256,33 @@ class SpreadsheetExcelService
} }
$column++; $column++;
} }
$span = chr(ord($span) -1); $span = chr(ord($span) - 1);
self::$colum = $column; self::$colum = $column;
self::$sheet->getDefaultRowDimension()->setRowHeight(self::$height); 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; return $this;
} }
public function setExcelEnd(array $data) public function setExcelEnd(array $data)
{ {
if(!empty($data)){ if (!empty($data)) {
foreach ($data as $key => $value){ foreach ($data as $key => $value) {
$i = self::$colum + $key ; $i = self::$colum + $key;
self::$sheet->mergeCells('A'.$i.':' . self::$cells.$i); self::$sheet->mergeCells('A' . $i . ':' . self::$cells . $i);
self::$sheet->setCellValue('A'.$i, $value); self::$sheet->setCellValue('A' . $i, $value);
self::$sheet->getStyle('A'.$i)->getFont()->setName('宋体'); self::$sheet->getStyle('A' . $i)->getFont()->setName('宋体');
self::$sheet->getStyle('A'.$i)->getFont()->setSize(16); self::$sheet->getStyle('A' . $i)->getFont()->setSize(16);
self::$sheet->getStyle('A'.$i)->getFont()->setBold(true); 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)->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; return $this;
} }
@ -291,21 +295,21 @@ class SpreadsheetExcelService
* @param $path 是否保存文件文件 * @param $path 是否保存文件文件
* @return 保存文件return string * @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($fileName)) $fileName = date('YmdHis') . time();
if(empty($suffix)) $suffix = 'xlsx'; if (empty($suffix)) $suffix = 'xlsx';
// 重命名表UTF8编码不需要这一步 // 重命名表UTF8编码不需要这一步
if (mb_detect_encoding($fileName) != "UTF-8") $fileName = iconv("utf-8", "gbk//IGNORE", $fileName); if (mb_detect_encoding($fileName) != "UTF-8") $fileName = iconv("utf-8", "gbk//IGNORE", $fileName);
$save_path = self::$path.$path; $save_path = self::$path . $path;
$root_path = app()->getRootPath().'public/'.$save_path; $root_path = app()->getRootPath() . 'public/' . $save_path;
if(!is_dir($root_path)) mkdir($root_path, 0755,true); if (!is_dir($root_path)) mkdir($root_path, 0755, true);
$spreadsheet = self::$spreadsheet; $spreadsheet = self::$spreadsheet;
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($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 * @author Qinii
* @day 3/15/21 * @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)); $ext = ucfirst(pathinfo($filePath, PATHINFO_EXTENSION));
$ret = []; $ret = [];
if (in_array($ext, ['Xlsx', 'Xls'])) { if (in_array($ext, ['Xlsx', 'Xls'])) {
@ -328,16 +332,16 @@ class SpreadsheetExcelService
$reader->setReadDataOnly(true); $reader->setReadDataOnly(true);
$spreadsheet = $reader->load($filePath); $spreadsheet = $reader->load($filePath);
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$row_count = $sheet->getHighestDataRow();//取得总行数 $row_count = $sheet->getHighestDataRow(); //取得总行数
for ($row = $startRow; $row <= $row_count; $row++) { for ($row = $startRow; $row <= $row_count; $row++) {
$con = []; $con = [];
$item = []; $item = [];
$one = []; $one = [];
// $getK = $sheet->getCell('A'.$row)->getValue(); // $getK = $sheet->getCell('A'.$row)->getValue();
// if ($getK) { // if ($getK) {
// $getV = $sheet->getCell('B'.$row)->getValue(); // $getV = $sheet->getCell('B'.$row)->getValue();
// $one[] = [$getK => $getV]; // $one[] = [$getK => $getV];
// } // }
if (!empty($where)) { if (!empty($where)) {
foreach ($where as $k => $v) { foreach ($where as $k => $v) {
$con_value = $sheet->getCell($v . $row)->getValue(); $con_value = $sheet->getCell($v . $row)->getValue();
@ -369,26 +373,29 @@ class SpreadsheetExcelService
* @author Qinii * @author Qinii
* @day 5/7/21 * @day 5/7/21
*/ */
public function checkImport($filePath,$check = [],$is_limit=false,$count=1000) public function checkImport($filePath, $check = [], $is_limit = false, $count = 1000)
{ {
try {
$ext = ucfirst(pathinfo($filePath, PATHINFO_EXTENSION)); $ext = ucfirst(pathinfo($filePath, PATHINFO_EXTENSION));
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($ext); $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($ext);
$spreadsheet = $reader->load($filePath); $spreadsheet = $reader->load($filePath);
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
if($is_limit==true){ if ($is_limit == true) {
$limit=$sheet->getHighestRow(); $limit = $sheet->getHighestRow();
if($limit>$count){ if ($limit > $count) {
throw new ValidateException('导入的条数超过限制数量:'.$count.',当前表格数量'.$limit); throw new ValidateException('导入的条数超过限制数量:' . $count . ',当前表格数量' . $limit);
} }
} }
if(!empty($check)){ if (!empty($check)) {
foreach ($check as $s => $c){ foreach ($check as $s => $c) {
$_c = $sheet->getCell($s)->getValue(); $_c = $sheet->getCell($s)->getValue();
if($_c !== $c) throw new ValidateException('表格"'.$s.'"不是"'.$c.'"不可导入'); if ($_c !== $c) throw new ValidateException('表格"' . $s . '"不是"' . $c . '"不可导入');
} }
} }
} catch (\Exception $e) {
throw new ValidateException('表格中有无法解析的编码,请重新设置表格');
}
return true; return true;
} }
} }

33
route/middle.php Executable file
View File

@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
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);