MoneyIn.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\admin\controller\trade;
  3. use app\common\model\Users;
  4. use think\Db;
  5. use Exception;
  6. use app\common\controller\Backend;
  7. use app\common\model\MoneyLog;
  8. use think\exception\DbException;
  9. use think\exception\PDOException;
  10. use think\exception\ValidateException;
  11. /**
  12. * 充值记录管理
  13. *
  14. * @icon fa fa-circle-o
  15. */
  16. class MoneyIn extends Backend
  17. {
  18. /**
  19. * Mongyin模型对象
  20. * @var \app\admin\model\trade\Mongyin
  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\MoneyIn;
  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 ($status == $this->model::Success) {
  79. (new MoneyLog())->change($row->user_id, $row->amount, MoneyLog::Recharge, '', '充值');
  80. $user_info = (new Users())->where('id', $row->user_id)->find();
  81. if($user_info && $user_info['freeze'] < 0){
  82. //卡单中,充值时消除卡单状态
  83. $freeze = ($row->amount + $user_info['freeze']) >= 0 ? 0 : ($row->amount + $user_info['freeze']);
  84. (new Users())->where('id', $user_info['id'])->update(['freeze' => $freeze]);
  85. }
  86. }
  87. $result = $row->allowField(true)->save(['status' => $status, 'admin_id'=>$this->auth->id]);
  88. //累积充值金额
  89. //(new Users())->where('id', $row->user_id)->setInc('money_in_sum', $row->amount);
  90. Db::commit();
  91. } catch (ValidateException|PDOException $e) {
  92. Db::rollback();
  93. $this->error($e->getMessage());
  94. }
  95. if (false === $result) {
  96. $this->error(__('No rows were updated'));
  97. }
  98. $this->success();
  99. }
  100. }