调货单物流跟踪信息

pull/1/head
ztt 1 year ago
parent e86bb22367
commit fbffb4cd35
  1. 33
      app/api/controller/Order.php
  2. 22
      app/api/service/Order.php
  3. 120
      app/api/service/TransferRecord.php
  4. 2
      app/common/library/express/provider/driver/Kd100.php
  5. 21
      app/common/model/TransferRecord.php
  6. 46
      app/common/service/Express.php

@ -19,7 +19,8 @@ use app\api\service\User as UserService;
use app\api\service\Order as OrderService;
use app\common\service\qrcode\Extract as ExtractQRcode;
use cores\exception\BaseException;
use app\common\model\TransferRecord;
use app\api\service\TransferRecord;
use app\common\model\TransferRecord as TransferRecordModel;
use app\common\model\UploadFile;
/**
@ -93,7 +94,7 @@ class Order extends Controller
]);
}
/**
* 获取物流跟踪信息
* 获取调货单物流跟踪信息
* @param int $orderId 订单ID
* @return Json
* @throws BaseException
@ -103,23 +104,11 @@ class Order extends Controller
*/
public function expressSearch(string $expressNo): Json
{
$items = [
[
'time' => "2021-12-15 17:19:28",
"context"=>"【杭州市】您的包裹已存放至【驿站】,记得早点来取它回家!",
"ftime"=>"2021-12-15 17:19:28",
"areaCode"=>"CN330102000000",//本数据元对应的行政区域编码,resultv2=1或者resultv2=4才会展示
"areaName"=>"浙江,杭州市,上城区",//本数据元对应的行政区域名称,resultv2=1或者resultv2=4才会展示
"status"=>"投柜或驿站",//本数据元对应的物流状态名称或者高级物流状态名称,resultv2=1或者resultv2=4才会展示
"location"=>"浙江省 杭州市 上城区", //本数据元对应的快件当前地点,resultv2=4才会展示
"areaCenter"=>"120.184349,30.25446", //本数据元对应的行政区域经纬度,resultv2=4才会展示
"areaPinYin"=>"shang cheng qu",//本数据元对应的行政区域拼音,resultv2=4才会展示
"statusCode"=>"501",//本数据元对应的高级物流状态值,resultv2=4才会展示
],
];
$express['items'] = $items;
$express['express_name'] = "顺丰";
$express['express_no'] = "1222222222222";
$transferRecordService = new TransferRecord();
$data = $transferRecordService->getExpressByExpressNo($expressNo);
$express['items'] = $data['traces'];
$express['express_name'] = $data['express']['express_name'];
$express['express_no'] = $data['express_no'];
return $this->renderSuccess($express);
}
/**
@ -260,7 +249,7 @@ class Order extends Controller
if (!empty($params['search'])) {
$where[] = ['goods_sn', 'like', "%{$params["search"]}%"];
}
$list = TransferRecord::where('status',1)
$list = TransferRecordModel::where('status',1)
->where($where)
->order("id desc")
->paginate(10)->each(function ($item, $key) {
@ -303,7 +292,7 @@ class Order extends Controller
$params = $this->request->param();
$id = $params['id']??0;
unset($params['id']);
TransferRecord::where('id',$id)->update($params);
TransferRecordModel::where('id',$id)->update($params);
return $this->renderSuccess('ok');
}
@ -313,7 +302,7 @@ class Order extends Controller
$storeid = request()->header()['storeid'];
$params['user_id'] = \app\api\service\User::getCurrentLoginUserId();
$params['store_id'] = $storeid;
TransferRecord::create($params);
TransferRecordModel::create($params);
return $this->renderSuccess('ok');
}

@ -41,9 +41,9 @@ class Order extends OrderService
// 获取发货单列表
$model = new DeliveryModel;
$list = $model->getList($orderId);
// echo "<pre>";
// print_r($list);
// exit();
// echo "<pre>";
// print_r($list->toArray());
// exit();
// 整理物流跟踪信息
return $this->getExpressTraces($orderId, $list);
}
@ -65,9 +65,9 @@ class Order extends OrderService
// 整理物流跟踪信息
$Express = new ExpressService;
foreach ($list as $item) {
// echo "<pre>";
// print_r($item['express']);
// exit();
// echo "<pre>";
// print_r($item['express']);
// exit();
if (!empty($item['express'])) {
$item['traces'] = $Express->traces(
$item['express'],
@ -97,4 +97,14 @@ class Order extends OrderService
->where('order.is_delete', '=', 0)
->sum('order_goods.total_num');
}
public static function getExpressByExpressNo($expressNo) {
$expressService = new ExpressService();
// $Express->traces(
// $item['express'],
// $item['express_no'],
// $address,
// $this->getStoreId()
// );
}
}

@ -0,0 +1,120 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\api\service;
use app\api\model\Order as OrderModel;
use app\api\model\order\Delivery as DeliveryModel;
use app\api\model\OrderAddress as OrderAddressModel;
use app\common\service\BaseService;
use app\common\service\Order as OrderService;
use app\common\service\Express as ExpressService;
use app\common\enum\order\OrderStatus as OrderStatusEnum;
use cores\exception\BaseException;
/**
* 调货服务类
* Class Order
* @package app\common\service
*/
class TransferRecord extends BaseService
{
/**
* 获取物流信息
* @param int $orderId 订单ID
* @return mixed
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function express(int $orderId)
{
// 获取发货单列表
$model = new DeliveryModel;
$list = $model->getList($orderId);
// echo "<pre>";
// print_r($list->toArray());
// exit();
// 整理物流跟踪信息
return $this->getExpressTraces($orderId, $list);
}
/**
* 整理物流跟踪信息
* @param int $orderId 订单ID
* @param $list
* @return mixed
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getExpressTraces(int $orderId, $list)
{
// 订单收货地址
$address = OrderAddressModel::detail(['order_id' => $orderId]);
// 整理物流跟踪信息
$Express = new ExpressService;
foreach ($list as $item) {
if (!empty($item['express'])) {
$item['traces'] = $Express->traces(
$item['express'],
$item['express_no'],
$address,
$this->getStoreId()
);
}
}
return $list;
}
/**
* 获取某商品的购买件数
* @param int $userId 用户ID
* @param int $goodsId 商品ID
* @param int $orderSource
* @return int
*/
public static function getGoodsBuyNum(int $userId, int $goodsId, int $orderSource): int
{
return (int) (new OrderModel)->setBaseQuery('order', [['order_goods', 'order_id']])
->where('order_goods.user_id', '=', $userId)
->where('order_goods.goods_id', '=', $goodsId)
->where('order.order_source', '=', $orderSource)
->where('order.order_status', '<>', OrderStatusEnum::CANCELLED)
->where('order.is_delete', '=', 0)
->sum('order_goods.total_num');
}
/**
* 获取仓库物流信息
* @param $expressNo
* @return \app\common\model\TransferRecord|array|mixed|\think\Model
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getExpressByExpressNo($expressNo) {
$expressService = new ExpressService();
$transferRecord = \app\common\model\TransferRecord::getList($expressNo);
//物流追踪
$transferRecord['traces'] = $expressService->traces(
$transferRecord->express,
$expressNo,
$transferRecord['receiver_phone'],
$this::getStoreId()
);
return $transferRecord;
}
}

@ -52,7 +52,7 @@ class Kd100 extends Driver
log_record(['name' => '查询物流轨迹', 'provider' => 'kd100', 'param' => $param, 'result' => $data]);
// 记录错误信息
if (isset($data['returnCode']) || !isset($data['data'])) {
throwError('快递100物流查询API失败:' . $data['message']);
throwError('快递100物流查询API失败:' . $data['message']. $data['returnCode']);
}
// 格式化返回的数据
return $this->formatTraces($data['data']);

@ -13,9 +13,10 @@ declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use think\model\relation\BelongsTo;
/**
* 模型类:购物车
* 模型类:调货记录表
* Class Cart
* @package app\common\model
*/
@ -27,5 +28,23 @@ class TransferRecord extends BaseModel
// 定义主键
protected $pk = 'id';
public static function getList($expressNo)
{
return self::with(['express'])
->where('express_no', '=', $expressNo)
->find();
}
/**
* 关联物流公司记录
* @return BelongsTo
*/
public function express(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Express", 'express_id');
}
}

@ -12,6 +12,7 @@ declare (strict_types=1);
namespace app\common\service;
use http\Encoding\Stream;
use think\facade\Cache;
use app\common\enum\Setting as SettingEnum;
use app\common\model\store\Setting as SettingModel;
@ -39,6 +40,7 @@ class Express extends BaseService
*/
public function traces($express, string $expressNo, $address, int $storeId): array
{
// var_dump($expressNo);
// 获取物流查询API配置项
$config = $this->getTracesConfig($storeId);
// 物流公司编码
@ -57,8 +59,8 @@ class Express extends BaseService
$result = ExpressFacade::store($config['default'])
->setOptions($config['providerConfig'][$config['default']])
->query($code, $expressNo);
var_dump($result);
exit();
// var_dump($result);
// exit();
// 记录缓存, 有效期60分钟
Cache::set($cacheIndex, $result, 60 * 60);
return $result;
@ -81,4 +83,44 @@ class Express extends BaseService
}
return $config['traces'];
}
/**
* 仓库物流轨迹查询
* @param mixed $express 物流公司记录
* @param string $expressNo 物流单号
* @param string $receiver_phone 收货人手机号码
* @param int $storeId 商城ID
* @return array
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function transferTraces($express, string $expressNo, string $receiver_phone, int $storeId): array
{
// var_dump($expressNo);
// 获取物流查询API配置项
$config = $this->getTracesConfig($storeId);
// 物流公司编码
$code = $config['default'] === 'kd100' ? $express['kuaidi100_code'] : $express['kdniao_code'];
// 获取缓存的数据
$cacheIndex = "expressTraces_{$code}_$expressNo";
if (Cache::has($cacheIndex)) {
return Cache::get($cacheIndex);
}
// 使用阿里云查询顺丰时 物流单号需要加上手机尾号
if ($config['default'] == 'aliyun' && $code === 'SF') {
$lastPhoneNumber = mb_substr($receiver_phone, -4);
$expressNo = "{$expressNo}:$lastPhoneNumber";
}
// 请求API查询物流轨迹
$result = ExpressFacade::store($config['default'])
->setOptions($config['providerConfig'][$config['default']])
->query($code, $expressNo);
// var_dump($result);
// exit();
// 记录缓存, 有效期60分钟
Cache::set($cacheIndex, $result, 60 * 60);
return $result;
}
}
Loading…
Cancel
Save