Txjl.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\admin\controller\txjl;
  3. use app\common\controller\Backend;
  4. use app\common\model\MoneyLog;
  5. use app\admin\model\Admin;
  6. use think\Session;
  7. use think\Db;
  8. /**
  9. * 会员管理
  10. *
  11. * @icon fa fa-user
  12. */
  13. class Txjl extends Backend
  14. {
  15. protected $relationSearch = true;
  16. /**
  17. * @var \app\admin\model\User
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = model('Txjl');
  24. }
  25. /**
  26. * 查看
  27. */
  28. public function index()
  29. {
  30. //设置过滤方法
  31. $this->request->filter(['strip_tags']);
  32. if ($this->request->isAjax()) {
  33. //如果发送的来源是Selectpage,则转发到Selectpage
  34. if ($this->request->request('keyField')) {
  35. return $this->selectpage();
  36. }
  37. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  38. $total = $this->model
  39. ->with('user')
  40. ->where($where)
  41. ->order($sort, $order)
  42. ->count();
  43. $list = $this->model
  44. ->with('user')
  45. ->where($where)
  46. ->order($sort, $order)
  47. ->limit($offset, $limit)
  48. ->select();
  49. $result = array("total" => $total, "rows" => $list);
  50. return json($result);
  51. }
  52. return $this->view->fetch();
  53. }
  54. /**
  55. * 编辑
  56. */
  57. public function edit($ids = NULL)
  58. {
  59. $row = $this->model->get($ids);
  60. if (!$row)
  61. $this->error(__('No Results were found'));
  62. if ($this->request->isPost()) {
  63. $params = $this->request->post("row/a");
  64. if($params['iscl']==3 and $row['iscl']!=3){
  65. if($row['uid']>0){
  66. $this->bohui($row['uid'],$row['money'],'提现驳回');
  67. }
  68. if($row['admin_id']>0){
  69. $this->htbohui($row['admin_id'],$row['money'],'提现驳回');
  70. }
  71. }
  72. }
  73. return parent::edit($ids);
  74. }
  75. public function add()
  76. {
  77. return parent::add();
  78. }
  79. public function info($pid = NULL)
  80. {
  81. $row = $this->model->get($pid);
  82. if (!$row)
  83. $this->error(__('No Results were found'));
  84. return parent::edit($pid);
  85. }
  86. public function htbohui($uid,$money,$tp='提现驳回'){
  87. $vadmin=Db::name('admin')->where('id',$uid)->find();
  88. if(!$vadmin){
  89. $this->error('会员id不正确');
  90. }
  91. Db::startTrans();
  92. try {
  93. $moneys=$money;
  94. //更新会员信息
  95. $before = $vadmin['money'];
  96. $after = $vadmin['money'] + $moneys;
  97. Db::name('admin') ->where('id',$uid)->setInc('money', $moneys);
  98. //写入日志
  99. Db::name('admin_money_log')->insertGetId(['admin_id' =>$uid, 'money' => $moneys,'createtime' => time(), 'before' => $before,'after' => $after, 'memo' => $tp]);
  100. Db::commit();
  101. }catch (Exception $e){
  102. Db::rollback();
  103. $this->error($e->getMessage());
  104. }
  105. }
  106. public function bohui($uid,$money,$tp='提现驳回'){
  107. $user = \app\common\model\User::getById($uid);
  108. if(!$user){
  109. $this->error('会员id不正确');
  110. }
  111. $before = $user->money;
  112. $after = $user->money + $money;
  113. Db::startTrans();
  114. try {
  115. $user->save(['money' => $after]);
  116. //写入日志
  117. MoneyLog::create(['user_id' => $user['id'], 'money' => $money, 'before' => $before, 'after' => $after, 'memo' => $tp]);
  118. Db::commit();
  119. }catch (Exception $e){
  120. Db::rollback();
  121. $this->error($e->getMessage());
  122. }
  123. }
  124. }