JSON_SUCCESS_STATUS
JSON_SUCCESS_STATUS = 1
订单售后服务 Class service
$view : \think\View
$request : \think\Request
__construct(\think\Request $request = null)
构造方法
\think\Request | $request | Request 对象 |
getUser(boolean $is_force = true) : \app\api\model\User|boolean|null
获取当前用户信息
boolean | $is_force |
validate(array $data, string|array $validate, array $message = array(), boolean $batch = false, mixed $callback = null) : array|string|true
验证数据
array | $data | 数据 |
string|array | $validate | 验证器名或者验证规则数组 |
array | $message | 提示信息 |
boolean | $batch | 是否批量验证 |
mixed | $callback | 回调方法(闭包) |
<?php
namespace app\api\controller\user;
use app\api\controller\Controller;
use app\api\model\Express as ExpressModel;
use app\api\model\OrderGoods as OrderGoodsModel;
use app\api\model\OrderRefund as OrderRefundModel;
/**
* 订单售后服务
* Class service
* @package app\api\controller\user\order
*/
class Refund 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 int $state
* @return array
* @throws \think\exception\DbException
*/
public function lists($state = -1)
{
$model = new OrderRefundModel;
$list = $model->getList($this->user['user_id'], (int)$state);
return $this->renderSuccess(compact('list'));
}
/**
* 申请售后
* @param $order_goods_id
* @return array
* @throws \think\exception\DbException
* @throws \Exception
*/
public function apply($order_goods_id)
{
// 订单商品详情
$goods = OrderGoodsModel::detail($order_goods_id);
if (isset($goods['refund']) && !empty($goods['refund'])) {
return $this->renderError('当前商品已申请售后');
}
if (!$this->request->isPost()) {
return $this->renderSuccess(['detail' => $goods]);
}
// 新增售后单记录
$model = new OrderRefundModel;
if ($model->apply($this->user, $goods, $this->request->post())) {
return $this->renderSuccess([], '提交成功');
}
return $this->renderError($model->getError() ?: '提交失败');
}
/**
* 售后单详情
* @param $order_refund_id
* @return array
* @throws \think\exception\DbException
*/
public function detail($order_refund_id)
{
// 售后单详情
$detail = OrderRefundModel::detail([
'user_id' => $this->user['user_id'],
'order_refund_id' => $order_refund_id
]);
if (empty($detail)) {
return $this->renderError('售后单不存在');
}
// 物流公司列表
$expressList = ExpressModel::getAll();
return $this->renderSuccess(compact('detail', 'expressList'));
}
/**
* 用户发货
* @param $order_refund_id
* @return array
* @throws \think\exception\DbException
*/
public function delivery($order_refund_id)
{
// 售后单详情
$model = OrderRefundModel::detail([
'user_id' => $this->user['user_id'],
'order_refund_id' => $order_refund_id
]);
if ($model->delivery($this->postData())) {
return $this->renderSuccess([], '操作成功');
}
return $this->renderError($model->getError() ?: '提交失败');
}
}