<?php
namespace app\api\controller\sharing;
use app\api\controller\Controller;
use app\api\model\Express as ExpressModel;
use app\api\model\sharing\OrderGoods as OrderGoodsModel;
use app\api\model\sharing\OrderRefund as OrderRefundModel;
class Refund extends Controller
{
private $user;
public function _initialize()
{
parent::_initialize();
$this->user = $this->getUser(); }
public function lists($state = -1)
{
$model = new OrderRefundModel;
$list = $model->getList($this->user['user_id'], (int)$state);
return $this->renderSuccess(compact('list'));
}
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() ?: '提交失败');
}
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'));
}
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() ?: '提交失败');
}
}