MoneyOut.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. public function _initialize()
  25. {
  26. parent::_initialize();
  27. $this->mapType = array();
  28. $this->model = new \app\common\model\MoneyOut;
  29. $this->assign('typeList', $this->model->getTypeList());
  30. }
  31. /**
  32. * 查看
  33. * @return string|Json
  34. * @throws \think\Exception
  35. * @throws DbException
  36. */
  37. public function index()
  38. {
  39. //设置过滤方法
  40. $this->request->filter(['strip_tags', 'trim']);
  41. if (false === $this->request->isAjax()) {
  42. return $this->view->fetch();
  43. }
  44. //如果发送的来源是 Selectpage,则转发到 Selectpage
  45. if ($this->request->request('keyField')) {
  46. return $this->selectpage();
  47. }
  48. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  49. //tab
  50. $type = $this->request->param('order_type/d');
  51. if($type > 0) $this->mapType['order_type'] = $type;
  52. $list = $this->model->with('users,admins')
  53. ->where($where)
  54. ->where($this->mapType)
  55. ->order($sort, $order)
  56. ->paginate($limit);
  57. $result = ['total' => $list->total(), 'rows' => $list->items()];
  58. return json($result);
  59. }
  60. /**
  61. * 审核
  62. * @param $ids
  63. * @return string
  64. * @throws DbException
  65. * @throws \think\Exception
  66. */
  67. public function review($ids = null, $status= 0)
  68. {
  69. $row = $this->model->get($ids);
  70. if (!$row) {
  71. $this->error(__('No Results were found'));
  72. }
  73. $result = false;
  74. Db::startTrans();
  75. try {
  76. //余额变动
  77. if(!in_array($status, [MoneyOutModel::Success, MoneyOutModel::Reject])){
  78. $this->error(__('参数有误'));
  79. }
  80. $amount = $row->amount;
  81. if($status == $this->model::Reject){
  82. (new MoneyLog())->change($row->user_id, $amount, MoneyLog::Reject, '', '驳回');
  83. }
  84. $result = $row->allowField(true)->save(['status'=>$status]);
  85. Db::commit();
  86. } catch (ValidateException|PDOException|Exception $e) {
  87. Db::rollback();
  88. $this->error($e->getMessage());
  89. }
  90. if (false === $result) {
  91. $this->error(__('No rows were updated'));
  92. }
  93. $this->success();
  94. }
  95. }