From c676680e9a659ea3813c9d7f3fe8044cd4d4c5ad Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 18 Apr 2023 10:06:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 136 +++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 95b242f6..643342ba 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -1134,7 +1134,7 @@ class StoreOrderRepository extends BaseRepository 'order_id' => $id, ]; $ret = $this->dao->getWhere($where); - if ($ret['is_virtual']) throw new ValidateException('虚拟商品只能虚拟发货'); + if ($ret['is_virtual']<98 && $ret['is_virtual']!=0) throw new ValidateException('虚拟商品只能虚拟发货'); $cargo = ''; $count = 0; foreach ($ret->orderProduct as $item) { @@ -2307,4 +2307,138 @@ class StoreOrderRepository extends BaseRepository if (file_exists($arrary['path'])) unlink($arrary['path']); } + public function setProduct(array $arrary, $merId) + { + //读取excel + $data = SpreadsheetExcelService::instance()->_import($arrary['path'], $arrary['sql'], $arrary['where'], 1); + if (!$data) return; + unset($data[0]); + $mer_cate_id=Db::name('store_category')->where('mer_id',$merId)->where('cate_name','默认分类')->value('store_category_id'); + if ($mer_cate_id==0){ + $mer_cate=['pid'=>0,'/']; + Db::name('store_category')->insert(); + } + foreach ($data as $datum) { + $find=Db::name('store_product')->where('mer_id', $merId)->where('bar_code', $datum['where']['bar_code'])->find(); + if ($find){ + Db::name('store_product')->where('product_id', $find['product_id'])->update($datum['value']); + }else{ + $store_category_id=Db::name('store_category')->where('mer_id',0)->where('cate_name',$datum['value']['cate_name'])->value('store_category_id'); + $datas = [ + "image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/def/03d76202301101051502568.png", + "slider_image" => [ + 0 => "https://lihai001.oss-cn-chengdu.aliyuncs.com/def/3d80f202301101051438680.png", + ], + "store_name" => $datum['value']['store_name'], + "store_info" => $datum['value']['store_name'], + "keyword" => $datum['value']['keyword'], + "bar_code" => $datum['value']['bar_code'], + "guarantee_template_id" => "", + "cate_id" => $store_category_id,//要修改 + "mer_cate_id" => [ + 0 => $mer_cate_id//要修改 + ], + "unit_name" => $datum['value']['unit_name'], + "sort" => 0, + "is_show" => "", + "is_good" => 0, + "is_gift_bag" => 0, + "integral_rate" => -1, + "video_link" => "", + "temp_id" => "", + "content" => "", + "spec_type" => 0, + "extension_type" => 0, + "attr" => [], + "mer_labels" => [], + "delivery_way" => [ + 0 => "2" + ], + "delivery_free" => 1, + "param_temp_id" => [], + "extend" => [], + "brand_id" => "", + "once_max_count" => 0, + "once_min_count" => 0, + "pay_limit" => 0, + "attrValue" => [ + [ + "image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/def/03d76202301101051502568.png", + "price" => $datum['value']['price'], + "cost" => $datum['value']['price'], + "ot_price" => $datum['value']['cost'], + "svip_price" => null, + "stock" => $datum['value']['stock'], + "bar_code" => $datum['value']['bar_code'], + "weight" => 0, + "volume" => 0, + ], + ], + "give_coupon_ids" => [], + "type" => 50,//供应链商品 + "svip_price" => 0, + "svip_price_type" => 0, + "params" => [], + "mer_id" => $merId, + "status" => 1, + "mer_status" => 1, + "rate" => 3, + ]; + $datum['value']['mer_id']=$merId; + Db::name('store_product')->insert($datum['value']); + } + } + halt($data); + $import_id = $arrary['import_id']; + Db::transaction(function () use ($data, $merId, $import_id) { + $result = []; + $num = 0; + $count = 0; + $status = 0; + foreach ($data as $datum) { + $value = []; + $ret = []; + if ($datum['where']) { + $count = $count + 1; + if (empty($datum['value']['delivery_id'])) { + $mark = '发货单号为空'; + } else { + $ret = $this->getSearch([]) + ->where('status', 0) + ->where('paid', 1) + ->where('order_type', 0) + ->where('mer_id', $merId) + ->where($datum['where']) + ->find(); + $mark = '数据有误或已发货'; + } + if ($ret) { + try { + $value = array_merge($datum['value'], ['status' => 1]); + $value['delivery_type'] = 1; + $this->delivery($ret['order_id'], $merId, $value); + + $status = 1; + $mark = ''; + + $num = $num + 1; + } catch (\Exception $exception) { + $mark = $exception->getMessage(); + } + } + $datum['where']['mark'] = $mark; + $datum['where']['mer_id'] = $merId; + $datum['where']['status'] = $status; + $datum['where']['import_id'] = $import_id; + $result[] = array_merge($datum['where'], $datum['value']); + } + } + // 记录入库操作 + if (!empty($result)) app()->make(StoreImportDeliveryRepository::class)->insertAll($result); + $_status = ($count == $num) ? 1 : (($num < 1) ? -1 : 10); + app()->make(StoreImportRepository::class)->update($import_id, ['count' => $count, 'success' => $num, 'status' => $_status]); + }); + if (file_exists($arrary['path'])) unlink($arrary['path']); + } + }