MoneyOut.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\admin\controller\trade;
  3. use think\Db;
  4. use Exception;
  5. use app\common\model\MoneyLog;
  6. use think\exception\DbException;
  7. use think\exception\PDOException;
  8. use app\common\controller\Backend;
  9. use think\exception\ValidateException;
  10. use app\common\model\MoneyOut as MoneyOutModel;
  11. /**
  12. * 提现记录管理
  13. *
  14. * @icon fa fa-circle-o
  15. */
  16. class MoneyOut extends Backend
  17. {
  18. /**
  19. * Mongyout模型对象
  20. * @var \app\admin\model\trade\Mongyout
  21. */
  22. protected $model = null;
  23. protected $mapType = null;
  24. protected $relationSearch = true;
  25. public function _initialize()
  26. {
  27. parent::_initialize();
  28. $this->mapType = array();
  29. $this->model = new \app\common\model\MoneyOut;
  30. $this->assign('typeList', $this->model->getTypeList());
  31. }
  32. /**
  33. * 查看
  34. * @return string|Json
  35. * @throws \think\Exception
  36. * @throws DbException
  37. */
  38. public function index()
  39. {
  40. //设置过滤方法
  41. $this->request->filter(['strip_tags', 'trim']);
  42. if (false === $this->request->isAjax()) {
  43. return $this->view->fetch();
  44. }
  45. //如果发送的来源是 Selectpage,则转发到 Selectpage
  46. if ($this->request->request('keyField')) {
  47. return $this->selectpage();
  48. }
  49. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  50. //tab
  51. $type = $this->request->param('order_type/d');
  52. if($type > 0) $this->mapType['order_type'] = $type;
  53. $list = $this->model->with('users,admins')
  54. ->where($where)
  55. ->where($this->mapType)
  56. ->order($sort, $order)
  57. ->paginate($limit);
  58. $result = ['total' => $list->total(), 'rows' => $list->items()];
  59. return json($result);
  60. }
  61. /**
  62. * 审核
  63. * @param $ids
  64. * @return string
  65. * @throws DbException
  66. * @throws \think\Exception
  67. */
  68. public function review($ids = null, $status= 0)
  69. {
  70. $row = $this->model->get($ids);
  71. if (!$row) {
  72. $this->error(__('No Results were found'));
  73. }
  74. $result = false;
  75. Db::startTrans();
  76. try {
  77. //余额变动
  78. if(!in_array($status, [MoneyOutModel::Success, MoneyOutModel::Reject])){
  79. $this->error(__('参数有误'));
  80. }
  81. $amount = $row->amount;
  82. if($status == $this->model::Reject){
  83. (new MoneyLog())->change($row->user_id, $amount, MoneyLog::Reject, '', '驳回');
  84. }
  85. $result = $row->allowField(true)->save(['status'=>$status, 'admin_id'=>$this->auth->id]);
  86. Db::commit();
  87. } catch (ValidateException|PDOException|Exception $e) {
  88. Db::rollback();
  89. $this->error($e->getMessage());
  90. }
  91. if (false === $result) {
  92. $this->error(__('No rows were updated'));
  93. }
  94. $this->success();
  95. }
  96. }