MoneyIn.php 2.5 KB

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