MoneyIn.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\admin\controller\trade;
  3. use think\Db;
  4. use Exception;
  5. use app\common\controller\Backend;
  6. use app\common\model\MoneyLog;
  7. use think\exception\DbException;
  8. use think\exception\PDOException;
  9. use think\exception\ValidateException;
  10. /**
  11. * 充值记录管理
  12. *
  13. * @icon fa fa-circle-o
  14. */
  15. class MoneyIn extends Backend
  16. {
  17. /**
  18. * Mongyin模型对象
  19. * @var \app\admin\model\trade\Mongyin
  20. */
  21. protected $model = null;
  22. protected $mapType = null;
  23. protected $relationSearch = true;
  24. public function _initialize()
  25. {
  26. parent::_initialize();
  27. $this->mapType = array();
  28. $this->model = new \app\common\model\MoneyIn;
  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 ($status == $this->model::Success) {
  78. (new MoneyLog())->change($row->user_id, $row->amount, MoneyLog::Recharge, '', '充值');
  79. }
  80. $result = $row->allowField(true)->save(['status' => $status, 'admin_id'=>$this->auth->id]);
  81. //累积充值金额
  82. //(new Users())->where('id', $row->user_id)->setInc('money_in_sum', $row->amount);
  83. Db::commit();
  84. } catch (ValidateException|PDOException $e) {
  85. Db::rollback();
  86. $this->error($e->getMessage());
  87. }
  88. if (false === $result) {
  89. $this->error(__('No rows were updated'));
  90. }
  91. $this->success();
  92. }
  93. }