Withdraw.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\Message;
  4. use app\common\controller\Backend;
  5. use think\Exception;
  6. use think\exception\PDOException;
  7. use think\exception\ValidateException;
  8. /**
  9. * 提现管理
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Withdraw extends Backend
  14. {
  15. /**
  16. * Withdraw模型对象
  17. * @var \app\admin\model\Withdraw
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\Withdraw;
  24. $typeList = [
  25. 'statusList' => $this->model->getStatusList(),
  26. 'typeList' => $this->model->getTypeList(),
  27. ];
  28. $this->view->assign($typeList);
  29. $this->assignconfig($typeList);
  30. }
  31. public function import()
  32. {
  33. parent::import();
  34. }
  35. /**
  36. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  37. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  38. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  39. */
  40. /**
  41. * 查看
  42. */
  43. public function index()
  44. {
  45. //当前是否为关联查询
  46. $this->relationSearch = true;
  47. //设置过滤方法
  48. $this->request->filter(['strip_tags', 'trim']);
  49. if ($this->request->isAjax()) {
  50. //如果发送的来源是Selectpage,则转发到Selectpage
  51. if ($this->request->request('keyField')) {
  52. return $this->selectpage();
  53. }
  54. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  55. $list = $this->model
  56. ->with(['user'])
  57. ->where($where)
  58. ->order($sort, $order)
  59. ->paginate($limit);
  60. foreach ($list as $row) {
  61. $row->getRelation('user')->visible(['nickname','money']);
  62. }
  63. $result = array("total" => $list->total(), "rows" => $list->items());
  64. return json($result);
  65. }
  66. return $this->view->fetch();
  67. }
  68. /**
  69. * 编辑
  70. */
  71. public function edit($ids = null)
  72. {
  73. $row = $this->model->get($ids);
  74. if (!$row) {
  75. $this->error(__('No Results were found'));
  76. }
  77. $adminIds = $this->getDataLimitAdminIds();
  78. if (is_array($adminIds)) {
  79. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  80. $this->error(__('You have no permission'));
  81. }
  82. }
  83. if ($this->request->isPost()) {
  84. $params = $this->request->post("row/a");
  85. if (!$params) {
  86. $this->error(__('Parameter %s can not be empty', ''));
  87. }
  88. $params = $this->preExcludeFields($params);
  89. $result = false;
  90. try {
  91. //是否采用模型验证
  92. if ($this->modelValidate) {
  93. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  94. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  95. $row->validateFailException(true)->validate($validate);
  96. }
  97. //状态:created=申请中,successed=成功,rejected=已拒绝
  98. $remark = '';
  99. if ($params['status'] == 'rejected') {//返回金额
  100. $user = model('User')->find($row['user_id']);
  101. $before = $user['money'];
  102. $remark = '提现'.$row['money'].'驳回';
  103. $res = model('Wallet')->lockChangeAccountRemain($row['user_id'],$row['money'],'+',$before,$remark,105,'money');
  104. if (!$res['status']) {
  105. throw new Exception($res['status']);
  106. }
  107. } elseif ($params['status'] == 'successed') {
  108. $remark = '提现'.$row['money'].'通过';
  109. }
  110. if (!empty($remark)) {
  111. //审核结果消息通知
  112. $messageModel = new Message();
  113. $messageModel->addMessage($row['user_id'],'提现审核通知',$remark);
  114. }
  115. $result = $row->allowField(true)->save($params);
  116. } catch (ValidateException|PDOException|Exception $e) {
  117. $this->error($e->getMessage());
  118. }
  119. if ($result == false) {
  120. $this->error(__('No rows were updated'));
  121. }
  122. $this->success();
  123. }
  124. $this->view->assign("row", $row);
  125. return $this->view->fetch();
  126. }
  127. }