Withdraws.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\admin\controller\account;
  3. use app\common\controller\Backend;
  4. use app\common\service\AccountWithdrawService;
  5. use app\common\service\CommonService;
  6. use think\Db;
  7. use think\exception\HttpResponseException;
  8. use think\exception\PDOException;
  9. use think\exception\ValidateException;
  10. /**
  11. * 账户提现记录管理
  12. *
  13. * @icon fa fa-circle-o
  14. */
  15. class Withdraws extends Backend
  16. {
  17. /**
  18. * Withdraws模型对象
  19. * @var \app\common\model\account\Withdraws
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\common\model\account\Withdraws;
  26. $this->view->assign("typeList", $this->model->getTypeList());
  27. $this->view->assign("statusList", $this->model->getStatusList());
  28. }
  29. /**
  30. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  31. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  32. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  33. */
  34. public function audit($ids)
  35. {
  36. $row = $this->model->get($ids);
  37. if (!$row) {
  38. $this->error(__('No Results were found'));
  39. }
  40. $adminIds = $this->getDataLimitAdminIds();
  41. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  42. $this->error(__('You have no permission'));
  43. }
  44. if (false === $this->request->isPost()) {
  45. $this->view->assign('row', $row);
  46. return $this->view->fetch();
  47. }
  48. $params = $this->request->post('row/a');
  49. if (empty($params)) {
  50. $this->error(__('Parameter %s can not be empty', ''));
  51. }
  52. $params = $this->preExcludeFields($params);
  53. Db::startTrans();
  54. try {
  55. //是否采用模型验证
  56. if ($this->modelValidate) {
  57. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  58. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  59. $row->validateFailException()->validate($validate);
  60. }
  61. if (in_array($params['status'], [CommonService::SUCCESS, CommonService::FAILED])) {
  62. AccountWithdrawService::approvalWithdraw($ids, $params['status'] == CommonService::SUCCESS, $params['remark'], $params['type']);
  63. }
  64. $result = $row->allowField(true)->save($params);
  65. if (false === $result) {
  66. $this->error(__('提现审核失败'));
  67. }
  68. Db::commit();
  69. $this->success();
  70. } catch (ValidateException|PDOException|\Exception $e) {
  71. Db::rollback();
  72. if ($e instanceof HttpResponseException) {
  73. throw $e;
  74. }
  75. $this->error($e->getMessage());
  76. }
  77. }
  78. }