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