OrderRefund.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\api\controller\mall;
  3. use app\common\controller\Api;
  4. use app\common\model\Refund;
  5. use app\common\service\RefundService;
  6. /**
  7. * 订单退款
  8. * @inheritdoc
  9. */
  10. class OrderRefund extends Api
  11. {
  12. protected $noNeedRight = "*";
  13. /**
  14. * 退款退货配置
  15. * @ApiMethod (POST)
  16. * @ApiParams (name=order_info_id,description=退货子订单ID)
  17. * @ApiParams (name=num,description=退货数量)
  18. * @ApiParams (name=num_install,description=退货安装数量)
  19. * @ApiReturnParams (name=reason,description=退款原因选项)
  20. * @ApiReturnParams (name=type,description=退货方式选项)
  21. */
  22. public function config()
  23. {
  24. $info=[
  25. 'reason'=>array_values(Refund::getReasons()),
  26. 'type'=>array_values(Refund::getRefundBys()),
  27. 'amount'=>0,
  28. ];
  29. $data=$this->_validate([
  30. 'order_info_id'=>['require','integer'],
  31. 'num'=>['require','integer','egt:0'],
  32. 'num_install'=>['require','integer','egt:0'],
  33. ]);
  34. $orderInfo=$this->auth->getUser()->orderInfo()->find($data['order_info_id']);
  35. if($orderInfo){
  36. list($amount,$amount_install)=RefundService::setOrderInfo($orderInfo,$data['num'],$data['num_install'])->amount();
  37. $info['amount']=bcadd($amount,$amount_install);
  38. }
  39. $this->success('', $info);
  40. }
  41. }