This commit is contained in:
mkm 2023-11-21 16:20:48 +08:00
parent 9b5ed65ae9
commit 33e96588a3
7 changed files with 239 additions and 291 deletions

View File

@ -268,8 +268,7 @@ class StoreOrderRepository extends BaseRepository
} }
} }
// 订单的类型 0 发货 1 自提 // 订单的类型 0 发货 1 自提
if ($order->order_type == 1 && $order->status != 10) if ($order->order_type == 1 && $order->status != 10) {
{
$order->verify_code = $this->verifyCode(); $order->verify_code = $this->verifyCode();
} }
$order->save(); $order->save();
@ -291,8 +290,7 @@ class StoreOrderRepository extends BaseRepository
$flag = false; $flag = false;
} }
} }
if ($order->order_type == 0) if ($order->order_type == 0) {
{
//发起队列物流信息处理 //发起队列物流信息处理
//event('order.sendGoodsCode', $order); //event('order.sendGoodsCode', $order);
Queue::push(SendGoodsCodeJob::class, $order); Queue::push(SendGoodsCodeJob::class, $order);
@ -334,7 +332,6 @@ class StoreOrderRepository extends BaseRepository
$_payPrice = bcsub($_payPrice, $_order_rate, 2); $_payPrice = bcsub($_payPrice, $_order_rate, 2);
// 结算各镇 小组佣金 // 结算各镇 小组佣金
event('order.paySuccessOrder', compact('order', '_order_rate')); event('order.paySuccessOrder', compact('order', '_order_rate'));
} }
if (!$presell) { if (!$presell) {
@ -1422,7 +1419,6 @@ class StoreOrderRepository extends BaseRepository
'change_type' => $statusRepository::ORDER_STATUS_TAKE, 'change_type' => $statusRepository::ORDER_STATUS_TAKE,
]; ];
$statusRepository->createSysLog($orderStatus); $statusRepository->createSysLog($orderStatus);
} }
if (isset($temp_code)) Queue::push(SendSmsJob::class, ['tempId' => $temp_code, 'id' => $order->order_id]); if (isset($temp_code)) Queue::push(SendSmsJob::class, ['tempId' => $temp_code, 'id' => $order->order_id]);
@ -1473,7 +1469,10 @@ class StoreOrderRepository extends BaseRepository
$whre['mer_id'] = $merId; $whre['mer_id'] = $merId;
$whre['is_system_del'] = 0; $whre['is_system_del'] = 0;
} }
$res = $this->dao->getWhere($where, '*', [ $res = $this->dao->getWhere(
$where,
'*',
[
'orderProduct', 'orderProduct',
'user' => function ($query) { 'user' => function ($query) {
$query->field('uid,real_name,nickname,is_svip,svip_endtime,phone'); $query->field('uid,real_name,nickname,is_svip,svip_endtime,phone');
@ -1816,7 +1815,8 @@ class StoreOrderRepository extends BaseRepository
return compact('count', 'list'); return compact('count', 'list');
} }
public function getOrderStatusV2($order) { public function getOrderStatusV2($order)
{
//订单状态 1 未支付 2待发货 3待收货 4待评价 5交易完成 6已退款 7待核销 8先货后款待结算 9待商家确认 //订单状态 1 未支付 2待发货 3待收货 4待评价 5交易完成 6已退款 7待核销 8先货后款待结算 9待商家确认
$order->order_status = 0; $order->order_status = 0;
if ($order->paid == 0) { if ($order->paid == 0) {
@ -2028,7 +2028,6 @@ class StoreOrderRepository extends BaseRepository
} else { } else {
$storeOrderStatusRepository->createAdminLog($orderStatus); $storeOrderStatusRepository->createAdminLog($orderStatus);
} }
}); });
event('order.verify', compact('order')); event('order.verify', compact('order'));
} }
@ -2245,7 +2244,6 @@ class StoreOrderRepository extends BaseRepository
if (count($couponId)) { if (count($couponId)) {
app()->make(StoreCouponUserRepository::class)->updates($couponId, ['status' => 0]); app()->make(StoreCouponUserRepository::class)->updates($couponId, ['status' => 0]);
} }
} }
//订单记录 //订单记录
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
@ -2514,33 +2512,81 @@ class StoreOrderRepository extends BaseRepository
$mer_cate['level'] = 1; $mer_cate['level'] = 1;
$mer_cate_id = Db::name('store_category')->insertGetId($mer_cate); $mer_cate_id = Db::name('store_category')->insertGetId($mer_cate);
} }
// $type=Db::name('merchant')->where('mer_id',$merId)->value('type_id');
$typeCode = Db::name('merchant_type')->where('mer_type_id', $merId)->value('type_code'); $typeCode = Db::name('merchant_type')->where('mer_type_id', $merId)->value('type_code');
$product_type = 0; $product_type = 0;
// if ($type==12){
if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) { if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) {
$product_type = 98; //供应链 $product_type = 98; //供应链
} }
foreach ($data as $datum) { foreach ($data as $datum) {
// $find=Db::name('store_product')->where('mer_id', $merId)->where('bar_code', $datum['where']['bar_code'])->find(); $find = Db::name('store_product')->where('mer_id', $merId)->where('store_name', $datum['value']['store_name'])->find();
// if ($find){ $attr_one = explode('|', $datum['value']['attr_one']);
// Db::name('store_product')->where('product_id', $find['product_id'])->update($datum['value']); $attr_two = explode('|', $datum['value']['attr_two']);
// }else{ $arr = [];
$store_category_id=Db::name('store_category')->where('mer_id',0)->where('cate_name',$datum['value']['cate_id'])->value('store_category_id'); if ($find) {
if ($store_category_id==null){ $store_product_attr_value = Db::name('store_product_attr_value')->where('product_id', $find['product_id'])->where('bar_code', $datum['value']['bar_code'])->find();
$store_category_id=438; if ($store_product_attr_value) {
Log::error('xls导入商品:已经导入过该规格了');
return false;
}
foreach ($attr_one as $kk => $vv) {
/**查询当前规格是否存在 */
$attr_values_find = Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)
->find();
if ($attr_values_find) {
$attr_values= $attr_values_find['attr_values'];
$attr_values = explode('-!-', $attr_values);
if (!in_array($vv, $attr_values)) {
$attr_values[] = $vv;
$attr_values = implode('-!-', $attr_values);
Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]);
}
} else {
$attr_values = $vv;
Db::name('store_product_attr')->insert(
[
'product_id' => $exist['product_id'],
'attr_name' => $kk, 'attr_values' => $attr_values
]
);
}
}
$attrValue['stock'] = 1;
$unique = app(ProductRepository::class)->setUnique($find['product_id'], $datum['value']['bar_code'], $product_type);
$attrValue['unique'] = $unique;
$attrValue['detail'] = json_encode($attrValue['detail']);
$attrValue['product_id'] = $find['product_id'];
$attrValue['mer_id'] = $merId;
Db::name('store_product_attr_value')->insert($attrValue);
} else {
$cate_id = 0;
$spec_type = 0;
$cate_id_one = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_one'])->value('store_category_id');
if ($cate_id_one) {
$cate_id_two = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_two'])->value('store_category_id');
if ($cate_id_two) {
$cate_id = $cate_id_two;
}
}
foreach ($attr_one as $k => $v) {
$arr[] = [
'value' => $v,
'detail' => [$attr_two[$k] ?? []],
'inputVisible' => false
];
$spec_type = 1;
} }
$datas = [ $datas = [
"image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png", "image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png",
"slider_image" => [ "slider_image" => [
0 => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png", 0 => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png",
], ],
"store_name" => $datum['value']['store_name'].' '.$datum['value']['specifications'], "store_name" => $datum['value']['store_name'],
"store_info" => $datum['value']['store_name'], "store_info" => $datum['value']['store_name'],
"keyword" => $datum['value']['keyword'], "keyword" => '',
"bar_code" => $datum['value']['bar_code'], "bar_code" => (int) $datum['value']['bar_code'],
"guarantee_template_id" => "", "guarantee_template_id" => "",
"cate_id" => $store_category_id,//要修改 "cate_id" => $cate_id,
"mer_cate_id" => [ "mer_cate_id" => [
0 => $mer_cate_id //要修改 0 => $mer_cate_id //要修改
], ],
@ -2554,14 +2600,15 @@ class StoreOrderRepository extends BaseRepository
"video_link" => "", "video_link" => "",
"temp_id" => "", "temp_id" => "",
"content" => "", "content" => "",
"spec_type" => 0, "spec_type" => $spec_type,
"extension_type" => 0, "extension_type" => 0,
"attr" => [], "attr" => $arr,
"mer_labels" => [], "mer_labels" => [],
"delivery_way" => [ "delivery_way" => [
0 => "2" 0 => "2",
1 => "1"
], ],
"delivery_free" => 1, "delivery_free" => 0,
"param_temp_id" => [], "param_temp_id" => [],
"extend" => [], "extend" => [],
"brand_id" => "", "brand_id" => "",
@ -2572,11 +2619,12 @@ class StoreOrderRepository extends BaseRepository
[ [
"image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png", "image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png",
"price" => $datum['value']['price'], "price" => $datum['value']['price'],
"cost" => $datum['value']['price'], "cost" => $datum['value']['cost'],
"ot_price" => $datum['value']['price'], "ot_price" => $datum['value']['price'],
"svip_price" => null, "svip_price" => null,
"stock" => $datum['value']['stock'], "procure_price" => $datum['value']['procure_price'],
"bar_code" => $datum['value']['bar_code'], "stock" => 1,
"bar_code" => (int)$datum['value']['bar_code'],
"weight" => 0, "weight" => 0,
"volume" => 0, "volume" => 0,
], ],
@ -2595,8 +2643,12 @@ class StoreOrderRepository extends BaseRepository
'data' => $datas, 'data' => $datas,
'product_type' => $product_type, 'product_type' => $product_type,
]; ];
$make = app()->make(ProductRepository::class);
$id = $make->create($datas, 98);
halt($id);
Queue::push(ProductImportJob::class, $data_list); Queue::push(ProductImportJob::class, $data_list);
} }
}
return true; return true;
} }
@ -2803,5 +2855,4 @@ class StoreOrderRepository extends BaseRepository
} }
$order->save(); $order->save();
} }
} }

View File

@ -224,6 +224,8 @@ class ProductRepository extends BaseRepository
public function create(array $data, int $productType = 0, $conType = 0) public function create(array $data, int $productType = 0, $conType = 0)
{ {
if (!$data['spec_type']) { if (!$data['spec_type']) {
halt($data['spec_type']);
$data['attr'] = []; $data['attr'] = [];
if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误'); if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误');
} }

View File

@ -341,8 +341,8 @@ class MerchantIntention extends BaseController
'name', 'name',
'code', 'code',
'images', 'images',
'merchant_category_name',
'mer_type_id', 'mer_type_id',
'merchant_category_id',
'social_credit_code', 'social_credit_code',
'area_id', 'area_id',
'street_id', 'street_id',
@ -360,14 +360,14 @@ class MerchantIntention extends BaseController
if ($data['mer_type_id'] && !app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id'])) { if ($data['mer_type_id'] && !app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id'])) {
throw new ValidateException('店铺类型不存在'); throw new ValidateException('店铺类型不存在');
} }
if ($data['merchant_category_name'] == '') { // if ($data['merchant_category_name'] == '') {
throw new ValidateException('商户分类,不能为空'); // throw new ValidateException('商户分类,不能为空');
} // }
$merchant_category_id=Db::name('merchant_category')->where('category_name',$data['merchant_category_name'])->value('merchant_category_id'); // $merchant_category_id=Db::name('merchant_category')->where('category_name',$data['merchant_category_name'])->value('merchant_category_id');
if(!$merchant_category_id){ // if(!$merchant_category_id){
throw new ValidateException('没有对应的商户分类,请联系工作人员添加'); // throw new ValidateException('没有对应的商户分类,请联系工作人员添加');
} // }
$data['merchant_category_id']=$merchant_category_id; // $data['merchant_category_id']=$merchant_category_id;
unset($data['code']); unset($data['code']);
return $data; return $data;
} }

View File

@ -89,29 +89,10 @@ class StoreImport extends BaseController
$res = $upload->getUploadInfo(); $res = $upload->getUploadInfo();
$path = rtrim(public_path(),'/').$res['dir']; $path = rtrim(public_path(),'/').$res['dir'];
$data = []; $data = [];
$type_id=Db::name('merchant')->where('mer_id',$this->request->merId())->value('type_id');
switch ($type){ switch ($type){
case 'product': case 'product':
$check =[ $this->getXlsList($type_id,$path);
'A1'=>'商品名称',
'B1'=>'商品简介',
'C1'=>'关键字',
'D1'=>'商品条码',
'E1'=>'分类',
'F1'=>'单位名',
'G1'=>'出售价',
'H1'=>'总库存',
'I1'=>'规格',
];
SpreadsheetExcelService::instance()->checkImport($path,$check);
$data = [
'mer_id' => $this->request->merId(),
'data' => [
'path' => $path,
'sql' => ['store_name' => 'A', 'store_info' => 'B', 'keyword' => 'C', 'bar_code' => 'D', 'cate_id' => 'E', 'unit_name' => 'F', 'price' => 'G', 'stock' => 'H', 'specifications' => 'I'],
'where' => ['bar_code' => 'D'],
]
];
app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id']);
return app('json')->success('开始导入数据,请稍后在列表中查看!'); return app('json')->success('开始导入数据,请稍后在列表中查看!');
break; break;
case 'delivery' : case 'delivery' :
@ -177,5 +158,38 @@ class StoreImport extends BaseController
} }
return app('json')->fail('数据类型错误'); return app('json')->fail('数据类型错误');
} }
public function getXlsList($type_id,$path){
if($type_id==12){
$check =[
'A1'=>'商品名称(必填)',
'B1'=>'平台一级类目(必填)',
'C1'=>'平台二级类目(必填)',
'D1'=>'店铺一级商品分类',
'E1'=>'店铺二级商品分类',
'F1'=>'规格组',
'G1'=>'规格值',
'H1'=>'销售单位',
'I1'=>'批发价(必填)',
'J1'=>'零售价(必填)',
'K1'=>'成本价',
'L1'=>'商品条码',
'M1'=>'商品品牌',
];
SpreadsheetExcelService::instance()->checkImport($path,$check);
$data = [
'mer_id' => $this->request->merId(),
'data' => [
'path' => $path,
'sql' => ['store_name' => 'A', 'cate_id_one' => 'B', 'cate_id_two' => 'C', 'cate_id_one_mer' => 'D', 'cate_id_one_two' => 'E',
'attr_one' => 'F', 'attr_two' => 'G', 'unit_name' => 'H', 'procure_price' => 'I','price'=>'J','cost'=>'K','bar_code'=>'L','brand_id'=>'M'],
'where' => ['bar_code' => 'L'],
]
];
app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id']);
}else{
}
}
} }

View File

@ -1,120 +0,0 @@
<?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\controller\merchant\store;
use app\common\repositories\store\ExcelRepository;
use app\common\repositories\store\order\StoreImportDeliveryRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use crmeb\jobs\ImportSpreadsheetExcelJob;
use crmeb\services\ExcelService;
use crmeb\services\SpreadsheetExcelService;
use crmeb\services\UploadService;
use think\App;
use crmeb\basic\BaseController;
use app\common\repositories\store\order\StoreImportRepository;
use think\facade\Queue;
class StoreImport extends BaseController
{
protected $repository;
/**
* Product constructor.
* @param App $app
* @param StoreImportRepository $repository
*/
public function __construct(App $app, StoreImportRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function lst()
{
[$page, $limit] = $this->getPage();
$where = $this->request->params(['status','date',['import_type','delivery'],'type']);
$where['mer_id'] = $this->request->merId();
$data = $this->repository->getList($where,$page,$limit);
return app('json')->success($data);
}
public function detail($id)
{
$where = [
'import_id' => $id,
'mer_id' => $this->request->merId()
];
[$page, $limit] = $this->getPage();
$data = app()->make(StoreImportDeliveryRepository::class)->getList($where,$page, $limit);
return app('json')->success($data);
}
public function export($id)
{
$where = [
'import_id' => $id,
'mer_id' => $this->request->merId()
];
[$page, $limit] = $this->getPage();
$data = app()->make(ExcelService::class)->importDelivery($where, $page, $limit);
return app('json')->success($data);
}
/**
* TODO 导入excel信息
* @return \think\response\Json
* @author Qinii
* @day 3/16/21
*/
public function Import($type)
{
$file = $this->request->file('file');
if (!$file) return app('json')->fail('请上传EXCEL文件');
$file = is_array($file) ? $file[0] : $file;
validate(["file|文件" => ['fileExt' => 'xlsx,xls',]])->check(['file' => $file]);
$upload = UploadService::create(1);
$ret = $upload->to('excel')->move('file');
if ($ret === false) return app('json')->fail($upload->getError());
$res = $upload->getUploadInfo();
$path = rtrim(public_path(),'/').$res['dir'];
$data = [];
switch ($type){
case 'delivery' :
SpreadsheetExcelService::instance()->checkImport($path,['E3' => '物流单号']);
$data = [
'mer_id' => $this->request->merId(),
'data' => [
'path' => $path,
'sql' => ['delivery_name' => 'D', 'delivery_id' => 'E',],
'where' => ['order_sn' => 'B',],
]
];
break;
default:
$data = SpreadsheetExcelService::instance()->_import($path,[],[],0);
break;
}
if(!empty($data)){
$res = $this->repository->create($this->request->merId(),'delivery');
$data['data']['import_id'] = $res->import_id;
// app()->make(StoreOrderRepository::class)->setWhereDeliveryStatus($data['data'],$data['mer_id']);
Queue::push(ImportSpreadsheetExcelJob::class,$data);
return app('json')->success('开始导入数据,请稍后在批量发货记录中查看!');
}
return app('json')->fail('数据类型错误');
}
}

View File

@ -23,7 +23,7 @@ class MerchantIntentionValidate extends Validate
'phone|手机号' => 'require|mobile', 'phone|手机号' => 'require|mobile',
'name|姓名' => 'require', 'name|姓名' => 'require',
'mer_name|姓名' => 'require|max:32', 'mer_name|姓名' => 'require|max:32',
'merchant_category_name|商户分类' => 'require', 'merchant_category_id|商户分类' => 'require',
'mer_type_id|店铺类型' => 'integer', 'mer_type_id|店铺类型' => 'integer',
'code|验证码' => 'require', 'code|验证码' => 'require',
'images|资质' => 'array', 'images|资质' => 'array',

View File

@ -325,6 +325,7 @@ class SpreadsheetExcelService
$ret = []; $ret = [];
if (in_array($ext, ['Xlsx', 'Xls'])) { if (in_array($ext, ['Xlsx', 'Xls'])) {
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($ext); $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($ext);
$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();//取得总行数