初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\app\physical;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\model\app\physical\OrderExpress;
|
||||
use app\common\model\app\physical\OrderExpressLog;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\library\app\physical\express\Express as libraryExpress;
|
||||
|
||||
/**
|
||||
* 物流接口
|
||||
*/
|
||||
class Express extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
protected $orderExpressModel = null;
|
||||
protected $orderExpressLogModel = null;
|
||||
protected $orderModel = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->orderExpressModel = new OrderExpress;
|
||||
$this->orderExpressLogModel = new OrderExpressLog;
|
||||
$this->orderModel = new Order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看物流记录
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$orderNo = $this->request->param('order_no', '');
|
||||
$expressNo = $this->request->param('express_no', '');
|
||||
|
||||
if (!$orderNo && !$expressNo) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
|
||||
$userId = $this->auth->id;
|
||||
|
||||
if ($orderNo) {
|
||||
$order = $this->orderModel
|
||||
->where('order_no', $orderNo)
|
||||
->where('user_id', $userId)
|
||||
->where('uniacid', UNIACID)
|
||||
->find();
|
||||
|
||||
if (!$order) {
|
||||
$this->error('订单不存在');
|
||||
}
|
||||
|
||||
$orderExpress = $this->orderExpressModel
|
||||
->where('order_id', $order['id'])
|
||||
->where('uniacid', UNIACID)
|
||||
->find();
|
||||
|
||||
if (!$orderExpress) {
|
||||
$this->error('暂无物流信息');
|
||||
}
|
||||
|
||||
$orderId = $order['id'];
|
||||
} else {
|
||||
$orderExpress = $this->orderExpressModel
|
||||
->where('express_no', $expressNo)
|
||||
->where('user_id', $userId)
|
||||
->where('uniacid', UNIACID)
|
||||
->find();
|
||||
|
||||
if (!$orderExpress) {
|
||||
$this->error('物流信息不存在');
|
||||
}
|
||||
|
||||
$orderId = $orderExpress['order_id'];
|
||||
}
|
||||
|
||||
$logs = $this->orderExpressLogModel
|
||||
->where('order_express_id', $orderExpress['id'])
|
||||
->where('uniacid', UNIACID)
|
||||
->order('change_date', 'desc')
|
||||
->select();
|
||||
|
||||
$logs = is_array($logs) ? $logs : $logs->toArray();
|
||||
|
||||
$result = [
|
||||
'express_name' => $orderExpress['express_name'],
|
||||
'express_code' => $orderExpress['express_code'],
|
||||
'express_no' => $orderExpress['express_no'],
|
||||
'status' => $orderExpress['status'],
|
||||
'status_text' => $this->getStatusText($orderExpress['status']),
|
||||
'order_id' => $orderId,
|
||||
'logs' => $logs
|
||||
];
|
||||
|
||||
$this->success('获取成功', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新物流信息
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
$orderNo = $this->request->param('order_no', '');
|
||||
$expressNo = $this->request->param('express_no', '');
|
||||
|
||||
if (!$orderNo && !$expressNo) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
|
||||
$userId = $this->auth->id;
|
||||
|
||||
if ($orderNo) {
|
||||
$order = $this->orderModel
|
||||
->where('order_no', $orderNo)
|
||||
->where('user_id', $userId)
|
||||
->where('uniacid', UNIACID)
|
||||
->find();
|
||||
|
||||
if (!$order) {
|
||||
$this->error('订单不存在');
|
||||
}
|
||||
|
||||
$orderExpress = $this->orderExpressModel
|
||||
->where('order_id', $order['id'])
|
||||
->where('uniacid', UNIACID)
|
||||
->find();
|
||||
|
||||
if (!$orderExpress) {
|
||||
$this->error('暂无物流信息');
|
||||
}
|
||||
|
||||
$orderId = $order['id'];
|
||||
} else {
|
||||
$orderExpress = $this->orderExpressModel
|
||||
->where('express_no', $expressNo)
|
||||
->where('user_id', $userId)
|
||||
->where('uniacid', UNIACID)
|
||||
->find();
|
||||
|
||||
if (!$orderExpress) {
|
||||
$this->error('物流信息不存在');
|
||||
}
|
||||
|
||||
$orderId = $orderExpress['order_id'];
|
||||
}
|
||||
|
||||
try {
|
||||
$physicalConfig = \app\common\model\app\Config::getConfig('physical');
|
||||
$aliyunConfig = [];
|
||||
$aliyunConfig['appcode'] = $physicalConfig['express_app_code'] ?? '';
|
||||
|
||||
$expressLib = new libraryExpress('aliyun', $aliyunConfig);
|
||||
|
||||
$address = \app\common\model\app\physical\OrderAddress::where([
|
||||
'order_id' => $orderId,
|
||||
'uniacid' => UNIACID
|
||||
])->find();
|
||||
|
||||
$expressLib->search([
|
||||
'order_id' => $orderId,
|
||||
'express_code' => $orderExpress['express_code'],
|
||||
'express_no' => $orderExpress['express_no'],
|
||||
'mobile' => $address ? $address['mobile'] : '',
|
||||
], $orderExpress);
|
||||
|
||||
$orderExpress = $this->orderExpressModel
|
||||
->where('id', $orderExpress['id'])
|
||||
->where('uniacid', UNIACID)
|
||||
->find();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error('刷新失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
$logs = $this->orderExpressLogModel
|
||||
->where('order_express_id', $orderExpress['id'])
|
||||
->where('uniacid', UNIACID)
|
||||
->order('change_date', 'desc')
|
||||
->select();
|
||||
|
||||
$logs = is_array($logs) ? $logs : $logs->toArray();
|
||||
|
||||
$result = [
|
||||
'express_name' => $orderExpress['express_name'],
|
||||
'express_code' => $orderExpress['express_code'],
|
||||
'express_no' => $orderExpress['express_no'],
|
||||
'status' => $orderExpress['status'],
|
||||
'status_text' => $this->getStatusText($orderExpress['status']),
|
||||
'order_id' => $orderId,
|
||||
'logs' => $logs
|
||||
];
|
||||
|
||||
$this->success('刷新成功', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*
|
||||
* @param string $status
|
||||
* @return string
|
||||
*/
|
||||
private function getStatusText($status)
|
||||
{
|
||||
$statusMap = [
|
||||
'noinfo' => '暂无信息',
|
||||
'transport' => '运输中',
|
||||
'delivery' => '派送中',
|
||||
'signfor' => '已签收',
|
||||
'refuse' => '拒签',
|
||||
'difficulty' => '疑难件',
|
||||
'invalid' => '无效单',
|
||||
'timeout' => '超时',
|
||||
'fail' => '派送失败',
|
||||
'back' => '退回'
|
||||
];
|
||||
|
||||
return $statusMap[$status] ?? '未知状态';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user