OrderInfoRefund.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. if($this->request->isGet()){
  65. $refund=$this->model->find($ids);
  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. ]);
  73. Db::startTrans();
  74. $refund=$this->model->lock(true)->where('id',$ids)->findOrFail();
  75. if(!$refund->allowAudit()){
  76. Db::rollback();
  77. $this->error('该申请已被审核');
  78. }
  79. $refund->makeAudit($data['refund_status']==1);
  80. Db::commit();
  81. $this->success();
  82. }
  83. }
  84. }