Refund.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\admin\controller\service\card;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 套餐卡订单
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Refund extends Backend
  11. {
  12. /**
  13. * Refund模型对象
  14. * @var \app\admin\model\service\card\Refund
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\service\card\Refund;
  21. $this->view->assign("paytypeList", $this->model->getPaytypeList());
  22. $this->view->assign("isServiceList", $this->model->getIsServiceList());
  23. $this->view->assign("statusList", $this->model->getStatusList());
  24. }
  25. public function index()
  26. {
  27. //设置过滤方法
  28. $this->request->filter(['strip_tags', 'trim']);
  29. if (false === $this->request->isAjax()) {
  30. return $this->view->fetch();
  31. }
  32. //如果发送的来源是 Selectpage,则转发到 Selectpage
  33. if ($this->request->request('keyField')) {
  34. return $this->selectpage();
  35. }
  36. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  37. $list = $this->model
  38. ->where($where)
  39. ->where('is_service','in','1,2,-1')
  40. ->order($sort, $order)
  41. ->paginate($limit);
  42. if($list)
  43. {
  44. foreach ($list as &$value)
  45. {
  46. $value->nickname = \app\admin\model\User::where(['id'=>$value->user_id])->value('nickname');
  47. }
  48. }
  49. $result = ['total' => $list->total(), 'rows' => $list->items()];
  50. return json($result);
  51. }
  52. public function agree($ids = null)
  53. {
  54. $row = $this->model->get($ids);
  55. if (!$row) {
  56. $this->error(__('No Results were found'));
  57. }
  58. $row->is_service != 1 && $this->error('请勿重复审核');
  59. $row->status != -2 && $this->error('套餐卡状态异常');
  60. Db::startTrans();
  61. try{
  62. \app\api\model\service\User::money(+$row->refund_price,$row->user_id,'套餐卡订单取消退款');
  63. $row->allowField(true)->save(['is_service'=>2,'status'=>-3,'updatetime'=>time()]);
  64. Db::commit();
  65. } catch (Exception $e) {
  66. Db::rollback();
  67. $this->error('退款通过失败',$e->getMessage());
  68. }
  69. $this->success('退款已通过');
  70. }
  71. public function refuse($ids = null)
  72. {
  73. $row = $this->model->get($ids);
  74. if (!$row) {
  75. $this->error(__('No Results were found'));
  76. }
  77. $row->is_service != 1 && $this->error('请勿重复审核');
  78. $row->status != -2 && $this->error('套餐卡状态异常');
  79. if($this->request->isPost()){
  80. $params = $this->request->post('row/a');
  81. Db::startTrans();
  82. try{
  83. $row->allowField(true)->save(['status'=>$row->original_status,'is_service'=>-1,'updatetime'=>time(),'note'=>$params['note']]);
  84. Db::commit();
  85. } catch (Exception $e) {
  86. Db::rollback();
  87. $this->error('退款拒绝失败',$e->getMessage());
  88. }
  89. $this->success('退款已拒绝');
  90. }
  91. $this->view->assign("id", $ids);
  92. return $this->view->fetch();
  93. }
  94. }