宝体数据调用接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

177 lines
5.3 KiB

<?php
namespace app\api\controller\user;
use app\api\controller\Controller;
use app\api\model\Order as OrderModel;
use app\common\service\qrcode\Extract as ExtractQRcode;
use app\common\enum\OrderType as OrderTypeEnum;
use app\common\enum\order\PayType as PayTypeEnum;
/**
* 用户订单管理
* Class Order
* @package app\api\controller\user
*/
class Order extends Controller
{
/* @var \app\api\model\User $user */
private $user;
/**
* 构造方法
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function _initialize()
{
parent::_initialize();
$this->user = $this->getUser(); // 用户信息
}
/**
* 我的订单列表
* @param $dataType
* @return array
* @throws \think\exception\DbException
*/
public function lists($dataType)
{
$model = new OrderModel;
$list = $model->getList($this->user['user_id'], $dataType);
return $this->renderSuccess(compact('list'));
}
/**
* 订单详情信息
* @param $order_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function detail($order_id)
{
// 订单详情
$order = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
// 该订单是否允许申请售后
$order['isAllowRefund'] = $order->isAllowRefund();
return $this->renderSuccess(compact('order'));
}
/**
* 获取物流信息
* @param $order_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function express($order_id)
{
// 订单信息
$order = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
if (!$order['express_no']) {
return $this->renderError('没有物流信息');
}
// 获取物流信息
/* @var \app\store\model\Express $model */
$model = $order['express'];
$express = $model->dynamic($model['express_name'], $model['express_code'], $order['express_no']);
if ($express === false) {
return $this->renderError($model->getError());
}
return $this->renderSuccess(compact('express'));
}
/**
* 取消订单
* @param $order_id
* @return array
* @throws \Exception
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function cancel($order_id)
{
$model = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
if ($model->cancel()) {
return $this->renderSuccess($model->getError() ?: '订单取消成功');
}
return $this->renderError($model->getError() ?: '订单取消失败');
}
/**
* 确认收货
* @param $order_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function receipt($order_id)
{
$model = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
if ($model->receipt()) {
return $this->renderSuccess();
}
return $this->renderError($model->getError());
}
/**
* 立即支付
* @param int $order_id 订单id
* @param int $payType 支付方式
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public function pay($order_id, $payType = PayTypeEnum::WECHAT)
{
// 订单详情
$model = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
// 判断商品状态、库存
if (!$model->checkGoodsStatusFromOrder($model['goods'])) {
return $this->renderError($model->getError());
}
$render = [
'order_id' => $model['order_id'], // 订单id
'pay_type' => $payType, // 支付方式
];
if ($payType == PayTypeEnum::WECHAT) {
$render['payment'] = $model->paymentByWechat($this->user);
} elseif ($payType == PayTypeEnum::BALANCE) {
if ($model->paymentByBalance($model['order_no'])) {
return $this->renderSuccess($render, '支付成功');
}
return $this->renderError($model->getError() ?: '支付失败', $render);
}
return $this->renderSuccess($render);
}
/**
* 获取订单核销二维码
* @param $order_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function extractQrcode($order_id)
{
// 订单详情
$order = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
// 判断是否为待核销订单
if (!$order->checkExtractOrder($order)) {
return $this->renderError($order->getError());
}
$Qrcode = new ExtractQRcode(
$this->wxapp_id,
$this->user,
$order_id,
OrderTypeEnum::MASTER
);
return $this->renderSuccess([
'qrcode' => $Qrcode->getImage(),
]);
}
}