Cash.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  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 Cash extends Backend
  14. {
  15. /**
  16. * Cash模型对象
  17. * @var \app\admin\model\Cash
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\Cash;
  24. $this->view->assign("payTypeList", $this->model->getPayTypeList());
  25. $this->view->assign("statusList", $this->model->getStatusList());
  26. }
  27. public function import()
  28. {
  29. parent::import();
  30. }
  31. /**
  32. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  33. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  34. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  35. */
  36. /**
  37. * 查看
  38. */
  39. public function index()
  40. {
  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(['user', 'admin'])
  51. ->where($where)
  52. ->order($sort, $order)
  53. ->paginate($limit);
  54. foreach ($list as $row) {
  55. $row->getRelation('user')->visible(['mobile']);
  56. }
  57. $result = ["total" => $list->total(), "rows" => $list->items()];
  58. return json($result);
  59. }
  60. return $this->view->fetch();
  61. }
  62. /**
  63. * 编辑
  64. */
  65. public function edit($ids = null)
  66. {
  67. $row = $this->model->get($ids);
  68. if (!$row) {
  69. $this->error(__('No Results were found'));
  70. }
  71. $adminIds = $this->getDataLimitAdminIds();
  72. if (is_array($adminIds)) {
  73. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  74. $this->error(__('You have no permission'));
  75. }
  76. }
  77. if ($this->request->isPost()) {
  78. $params = $this->request->post("row/a");
  79. if ($row['status'] == \app\admin\model\Cash::STATUS_SUCCESS || $row['status'] == \app\admin\model\Cash::STATUS_FAIL) {
  80. $this->error('当前状态不能修改');
  81. }
  82. if ($params) {
  83. $params = $this->preExcludeFields($params);
  84. $result = false;
  85. Db::startTrans();
  86. try {
  87. //是否采用模型验证
  88. if ($this->modelValidate) {
  89. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  90. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  91. $row->validateFailException(true)->validate($validate);
  92. }
  93. if ($params['status'] == \app\admin\model\Cash::STATUS_FAIL) {
  94. (new \app\admin\model\User())->where('id', $params['user_id'])->setInc('money', $row['money']);
  95. //减钱
  96. $detailModel = new \app\admin\model\Details();
  97. $data = [
  98. 'user_id' => $params['user_id'],
  99. 'fluctuate_type' => 1,
  100. 'msg' => '申请提现返回',
  101. 'amount' => $row['money'],
  102. 'assets_type' => 1,
  103. 'source_type' => 1,
  104. 'createtime' => time(),
  105. 'form_id' => $row['id'],
  106. ];
  107. $detailModel->insert($data);
  108. }
  109. $params['admin_id'] = $this->auth->id;
  110. $result = $row->allowField(true)->save($params);
  111. Db::commit();
  112. } catch (ValidateException $e) {
  113. Db::rollback();
  114. $this->error($e->getMessage());
  115. } catch (PDOException $e) {
  116. Db::rollback();
  117. $this->error($e->getMessage());
  118. } catch (Exception $e) {
  119. Db::rollback();
  120. $this->error($e->getMessage());
  121. }
  122. if ($result !== false) {
  123. $this->success();
  124. } else {
  125. $this->error(__('No rows were updated'));
  126. }
  127. }
  128. $this->error(__('Parameter %s can not be empty', ''));
  129. }
  130. $this->view->assign("row", $row);
  131. return $this->view->fetch();
  132. }
  133. }