OrderInfoRefund.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\admin\model\Refund as Refund;
  5. use think\Db;
  6. /**
  7. *
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class OrderInfoRefund extends Backend
  12. {
  13. /**
  14. * OrderInfoRefund模型对象
  15. * @var Refund
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new Refund;
  22. $this->assign('refund_types',$this->model::getRefundTypes());
  23. $this->assign('status',$this->model::getRefundStatus());
  24. }
  25. public function import()
  26. {
  27. parent::import();
  28. }
  29. /**
  30. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  31. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  32. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  33. */
  34. /**
  35. * 查看
  36. */
  37. public function index()
  38. {
  39. //当前是否为关联查询
  40. $this->relationSearch = false;
  41. //设置过滤方法
  42. $this->request->filter(['strip_tags', 'trim']);
  43. if ($this->request->isAjax()) {
  44. //如果发送的来源是Selectpage,则转发到Selectpage
  45. if ($this->request->request('keyField')) {
  46. return $this->selectpage();
  47. }
  48. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  49. $list = $this->model
  50. ->with(['order_info','user'])
  51. ->where($where)
  52. ->order($sort, $order)
  53. ->paginate($limit);
  54. foreach ($list as $row) {
  55. }
  56. $result = array("total" => $list->total(), "rows" => $list->items());
  57. return json($result);
  58. }
  59. $this->assign('reason',array_column(Refund::getReasons(),'value','key'));
  60. $this->assign('refund_by',array_column(Refund::getRefundBys(),'value','key'));
  61. return $this->view->fetch();
  62. }
  63. public function audit($ids){
  64. $refund=$this->model->find($ids);
  65. if($this->request->isGet()){
  66. $this->assign('refund',$refund);
  67. return $this->fetch();
  68. }else{
  69. $data=input('row/a');
  70. $this->validate($data,[
  71. 'refund_status'=>['require','in:1,2'],
  72. 'audit_remark|备注'=>['requireIf:refund_status,2'],
  73. ]);
  74. Db::startTrans();
  75. $refund=$this->model->lock(true)->where('id',$ids)->findOrFail();
  76. if($refund->has_money){
  77. $this->validate($data,[
  78. 'amount_last|退款金额'=>['require','float','gt:0'],
  79. ]);
  80. }
  81. if(!$refund->allowAudit()){
  82. Db::rollback();
  83. $this->error('该申请已被审核');
  84. }
  85. $refund->makeAudit($data['refund_status']==1,$data);
  86. Db::commit();
  87. $this->success();
  88. }
  89. }
  90. public function has_rec($ids){
  91. Db::startTrans();
  92. $refund=$this->model->lock(true)->find($ids);
  93. if(!$refund->need_rec){
  94. $this->error('用户未发货无法已收货');
  95. }
  96. $this->success();
  97. }
  98. }