|
@@ -0,0 +1,170 @@
|
|
|
+<?php
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Author: 萤火科技 <admin@yiovo.com>
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+declare (strict_types=1);
|
|
|
+
|
|
|
+namespace app\store\service\order;
|
|
|
+
|
|
|
+use app\common\library\express\Usps;
|
|
|
+use app\console\library\Tools;
|
|
|
+use app\store\model\{Order as OrderModel, order\Export as ExportModel, OrderAddress as OrderAddressModel};
|
|
|
+use app\common\library\helper;
|
|
|
+use app\common\service\BaseService;
|
|
|
+use app\common\service\Goods as GoodsService;
|
|
|
+use app\common\enum\order\{
|
|
|
+ PayType as PayTypeEnum,
|
|
|
+ PayStatus as PayStatusEnum,
|
|
|
+ OrderSource as OrderSourceEnum,
|
|
|
+ OrderStatus as OrderStatusEnum,
|
|
|
+ DeliveryType as DeliveryTypeEnum,
|
|
|
+ ReceiptStatus as ReceiptStatusEnum,
|
|
|
+ DeliveryStatus as DeliveryStatusEnum,
|
|
|
+ export\ExportStatus as ExportStatusEnum
|
|
|
+};
|
|
|
+use cores\exception\BaseException;
|
|
|
+use think\facade\Log;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 服务层:订单导出Excel
|
|
|
+ * Class Export
|
|
|
+ * @package app\store\service\order
|
|
|
+ */
|
|
|
+class DeliveryByF1 extends BaseService
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 设置用户的会员等级
|
|
|
+ * @param int $storeId
|
|
|
+ * @return array|bool
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function orderCreateYundan(int $orderId)
|
|
|
+ {
|
|
|
+ $Usps = new Usps();
|
|
|
+ // 请求查询接口
|
|
|
+ $token = $Usps->getItdidaToken();
|
|
|
+ if (empty($token)) {
|
|
|
+ Log::error('无有效的Iddida token');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $url = 'http://f1.itdida.com/itdida-api/yundans';
|
|
|
+ $params =
|
|
|
+ [
|
|
|
+ "baoGuanFangShi" => 0,
|
|
|
+ "baoGuoLeiXing" => 1,
|
|
|
+ "cardType" => 0,
|
|
|
+ "clientId" => $token,
|
|
|
+ "danJianList" => [
|
|
|
+ [
|
|
|
+ "chang" => 1,
|
|
|
+ "gao" => 1,
|
|
|
+ "kuan" => 1,
|
|
|
+ "origBoardNum" => 0,
|
|
|
+ "shiZhong" => 0.5,
|
|
|
+ "stackable" => true
|
|
|
+ ]
|
|
|
+ ],
|
|
|
+ "eori" => "",
|
|
|
+ "extraFreight" => 0,
|
|
|
+ "freightPaymentWay" => 0,
|
|
|
+ "fuShuiJin" => 0,
|
|
|
+ "guoJia" => "US",
|
|
|
+ "huoWuTeXing" => "带电",
|
|
|
+ "ioss" => "",
|
|
|
+ "jianShu" => 1,//to fix
|
|
|
+ "kapaiWaybill" => false,
|
|
|
+ //"keHuDanHao" => "",//todo fill
|
|
|
+ //"maiJiaId" => "",//to fill
|
|
|
+ "needDispatch" => false,
|
|
|
+ "needValidateAddress" => false,
|
|
|
+ "pushBackLabelAndInvoice" => false,
|
|
|
+ "qiTaDanHao1" => "JCX0415047275YQ",
|
|
|
+ "requiredChangeNo" => false,
|
|
|
+ "requiredTrackNo" => true,
|
|
|
+ "requiredZhuanDanFaPiao" => false,
|
|
|
+/* "shenBaoXinXiList" => [
|
|
|
+ [
|
|
|
+ "shenBaoBiZhong" => "USD",
|
|
|
+ "shenBaoDanJia" => 0,//todo fill 申报单价
|
|
|
+ "shenBaoHaiGuanBianMa" => "",
|
|
|
+ "shenBaoJinE" => 0,////todo fill 申报金额
|
|
|
+ "shenBaoPinMing" => "",//todo fill 品名
|
|
|
+ "shenBaoShuLiang" => 1,
|
|
|
+ "zhongWenPinMing" => ""//to fill
|
|
|
+ ],
|
|
|
+ ],*/
|
|
|
+ "shouHuoQuDao" => "美国专线小包普货",
|
|
|
+ "shouHuoShiZhong" => 0.500,
|
|
|
+ //"shouJianRenChengShi" => "",//to fill收货城市
|
|
|
+ //"shouJianRenDiZhi1" => "",//to fill收货地址
|
|
|
+ "shouJianRenDiZhi2" => "",
|
|
|
+ "shouJianRenDiZhi3" => "",
|
|
|
+ //"shouJianRenDianHua" => "",//to fill收货电话
|
|
|
+ "shouJianRenGongSi" => "",
|
|
|
+ //"shouJianRenXingMing" => "",//to fill收货人姓名
|
|
|
+ //"shouJianRenYouBian" => "",//to fill收货人邮编
|
|
|
+ "skuText" => "null,null,null",
|
|
|
+ "synPushBill" => false,
|
|
|
+ "tradeTerms" => "",
|
|
|
+ "useReferenceApi" => false,
|
|
|
+ "wuLiuFangShi" => 2,
|
|
|
+ //"zhouMing" => ""//to fill收货人州名
|
|
|
+
|
|
|
+ ];
|
|
|
+
|
|
|
+ $headers = [
|
|
|
+ "Content-type: application/json;charset=utf-8",
|
|
|
+ //'Content-Length: ' . strlen($data_string)),
|
|
|
+ "Authorization: {$token}",
|
|
|
+ "Accept: */*"
|
|
|
+ ];
|
|
|
+
|
|
|
+ $model = OrderModel::detail($orderId, ['goods', 'address']);
|
|
|
+
|
|
|
+ $params['keHuDanHao'] = $model['order_no'];
|
|
|
+ $params['maiJiaId'] = $model['user_id'];
|
|
|
+ $params['zhouMing'] = $model['address']['region']['code'];
|
|
|
+ $params['shouJianRenChengShi'] = $model['address']['city'];
|
|
|
+ $params['shouJianRenYouBian'] = $model['address']['zip_code'];
|
|
|
+
|
|
|
+ $params['shouJianRenDianHua'] = $model['address']['phone'];
|
|
|
+ $params['shouJianRenDiZhi1'] = $model['address']['detail'];
|
|
|
+ $params['shouJianRenXingMing'] = $model['address']['name'] . ' ' . $model['address']['last_name'];
|
|
|
+
|
|
|
+ $goodsList = [];
|
|
|
+ foreach ($model['goods'] as $good) {
|
|
|
+ $goodsList[] = [
|
|
|
+ "shenBaoBiZhong" => "USD",
|
|
|
+ "shenBaoDanJia" => $good['goods_price'],//todo fill 申报单价
|
|
|
+ "shenBaoHaiGuanBianMa" => "",
|
|
|
+ "shenBaoJinE" => $good['total_price'],//todo fill 申报金额
|
|
|
+ "shenBaoPinMing" => "vape",//$good['goods_name'],//todo fill 品名
|
|
|
+ "shenBaoShuLiang" => $good['total_num'],
|
|
|
+ "zhongWenPinMing" => "电子烟"//todo fill
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $params['shenBaoXinXiList'] = $goodsList;
|
|
|
+ $resJson = curl_post($url, [$params], $headers);
|
|
|
+ Log::write('itdida::' . $resJson);
|
|
|
+ $res = json_decode($resJson, true);
|
|
|
+ // 遍历整理数据
|
|
|
+ if (isset($res['data']) && $res['data'][0]['code'] == 200) {
|
|
|
+ if (!$model->delivery(['express_id' => 10001, 'express_no' => $res['data'][0]['zhuanDanHao']])) {
|
|
|
+ Log::write('发货失败orderId:' . $model['order_id'], 'error');
|
|
|
+ return ['code' => 200, 'message' => '发货成功',];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Log::write('itdida运单失败::orderNo:' . $model['order_no'] . $resJson, 'error');
|
|
|
+ return ['code' => 400, 'message' => $res['data'][0]['message']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|