Txmx.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\admin\controller\general;
  3. use app\admin\model\Admin;
  4. use app\common\controller\Backend;
  5. use fast\Random;
  6. use think\Session;
  7. use think\Validate;
  8. use app\common\model\Txjl;
  9. use think\Db;
  10. /**
  11. * 个人配置
  12. *
  13. * @icon fa fa-user
  14. */
  15. class Txmx extends Backend
  16. {
  17. /**
  18. * 查看
  19. */
  20. public function index()
  21. {
  22. //设置过滤方法
  23. $this->request->filter(['strip_tags']);
  24. if ($this->request->isAjax()) {
  25. $model = model('Txjl');
  26. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  27. $total = $model
  28. ->where($where)
  29. ->where('admin_id', $this->auth->id)
  30. ->order($sort, $order)
  31. ->count();
  32. $list = $model
  33. ->where($where)
  34. ->where('admin_id', $this->auth->id)
  35. ->order($sort, $order)
  36. ->limit($offset, $limit)
  37. ->select();
  38. $result = array("total" => $total, "rows" => $list);
  39. return json($result);
  40. }
  41. $admin = Admin::get($this->auth->id);
  42. Session::set("admin", $admin->toArray());
  43. return $this->view->fetch();
  44. }
  45. /**
  46. * 更新个人信息
  47. */
  48. public function update()
  49. {
  50. if ($this->request->isPost()) {
  51. $params = $this->request->post("row/a");
  52. if ($params) {
  53. $site=config('site');
  54. $money=$params['money'];
  55. if($money<$site['zstx']){
  56. $this->error($site['txbz']);
  57. }
  58. if(!$params['type']){
  59. $this->error('请填写提现类型');
  60. }
  61. if(!$params['name']){
  62. $this->error('请填写提现名字');
  63. }
  64. if(!$params['cord']){
  65. $this->error('请填写提现帐号');
  66. }
  67. $user_id=$this->auth->id;
  68. $vadmin=Db::name('admin')->where('id',$user_id)->find();
  69. if ($vadmin && $money != 0) {
  70. if($vadmin['money']<$money){
  71. $this->error('余额不足');
  72. }
  73. Db::startTrans();
  74. try {
  75. $moneys=$money;
  76. //更新会员信息
  77. $before = $vadmin['money'];
  78. $after = $vadmin['money'] - $moneys;
  79. Db::name('admin') ->where('id',$user_id)->setDec('money', $moneys);
  80. //写入日志
  81. Db::name('admin_money_log')->insertGetId(['admin_id' =>$user_id, 'money' => $moneys,'createtime' => time(),'before' => $before, 'after' => $after, 'memo' => '用户提现']);
  82. $site['txsxf']=isset($site['txsxf'])?$site['txsxf']:0;
  83. $sxf=$money*$site['txsxf'];
  84. $up=[
  85. 'admin_id' => $user_id,
  86. 'type' => $params['type'],
  87. 'name' => $params['name'],
  88. 'cord' => $params['cord'],
  89. 'money' => $money,
  90. 'moneydz' => $money-$sxf,
  91. 'sxf' => $sxf,
  92. 'iscl' => 1,
  93. 'islx' => 2,
  94. 'memo' => '后台用户提现'
  95. ];
  96. //写入提现记录
  97. Txjl::create($up);
  98. $admin = Admin::get($this->auth->id);
  99. Session::set("admin", $admin->toArray());
  100. Db::commit();
  101. $this->success('提交成功');
  102. }catch (Exception $e){
  103. Db::rollback();
  104. $this->error($e->getMessage());
  105. }
  106. }else{
  107. $this->error(__('金额不对'));
  108. }
  109. }
  110. $this->error();
  111. }
  112. return;
  113. }
  114. }