Money.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 会员中心
  7. */
  8. class Money extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //配置
  13. public function withdraw_config(){
  14. $data = [
  15. 'score' => model('wallet')->getWallet($this->auth->id,'score'),
  16. 'score_bufen' => model('wallet')->getWallet($this->auth->id,'shouyi'),
  17. 'min_withdrawal_money' => config('site.min_withdrawal_money'),
  18. 'max_withdrawal_money' => config('site.max_withdrawal_money'),
  19. 'type_1' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',1)->where('status',1)->field('realname,banknumber,bankname')->find(),
  20. 'type_2' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',2)->where('status',1)->field('realname,banknumber,bankname')->find(),
  21. 'type_3' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',3)->where('status',1)->field('realname,banknumber,bankname')->find(),
  22. ];
  23. $this->success(1,$data);
  24. }
  25. //提现
  26. public function scorewithdraw() {
  27. $type = input('type', 0, 'intval'); //类型:1=支付宝,2=微信,3=银行
  28. $from = input('from','all');
  29. if(!in_array($type,[1,2,3])){
  30. $this->error('参数错误');
  31. }
  32. if(!in_array($from,['all','bufen'])){
  33. $this->error('参数错误');
  34. }
  35. $check = Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('status',0)->find();
  36. if($check){
  37. $this->error('目前还有兑换在审核中,请稍后在兑换');
  38. }
  39. //开启事务
  40. Db::startTrans();
  41. //余额查询
  42. if($from == 'all'){
  43. $user_money = model('wallet')->getWallet($this->auth->id,'score');
  44. }else{
  45. $user_money = model('wallet')->getWallet($this->auth->id,'shouyi');
  46. }
  47. if ($user_money <= 0) {
  48. Db::rollback();
  49. $this->error('积分不足');
  50. }
  51. $data = [];
  52. $data['order_no'] = createUniqueNo('T',$this->auth->id);
  53. $data['user_id'] = $this->auth->id;
  54. $data['score'] = $user_money;
  55. $data['type'] = $type;
  56. $data['realname'] = input('realname','');
  57. $data['banknumber'] = input('banknumber','');
  58. $data['bankname'] = input('bankname','');
  59. $data['createtime'] = time();
  60. $data['status'] = 0;
  61. $data['from'] = ($from == 'all') ? 1 : 2; //all=1,bufen=2
  62. //添加提现记录
  63. $log_id = Db::name('user_withdraw')->insertGetId($data);
  64. if (!$log_id) {
  65. Db::rollback();
  66. $this->error('申请兑换失败');
  67. }
  68. //扣收益
  69. if($from == 'bufen'){
  70. $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'shouyi',-$data['score'],2,'积分兑换','user_withdraw',$log_id);
  71. if ($rs_wallet['status'] == false) {
  72. $this->error($rs_wallet['msg']);
  73. Db::rollback();
  74. }
  75. }
  76. //扣积分
  77. $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$data['score'],2,'积分兑换','user_withdraw',$log_id);
  78. if ($rs_wallet['status'] == false) {
  79. $this->error($rs_wallet['msg']);
  80. Db::rollback();
  81. }
  82. Db::commit();
  83. $this->success('申请兑换成功,请等待审核');
  84. }
  85. //废弃的提现
  86. public function old_scorewithdraw() {
  87. $type = input('type', 0, 'intval'); //类型:1=支付宝,2=微信,3=银行
  88. /*$money = input('score', '', 'intval');
  89. if ($money <= 0) {
  90. $this->error('请输入正确兑换积分');
  91. }*/
  92. $check = Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('status',0)->find();
  93. if($check){
  94. $this->error('目前还有兑换在审核中,请稍后在兑换');
  95. }
  96. //余额查询
  97. $user_money = model('wallet')->getWallet($this->auth->id,'score');
  98. /*if ($user_money < $money) {
  99. $this->error('余额不足');
  100. }*/
  101. if ($user_money <= 0) {
  102. $this->error('积分不足');
  103. }
  104. //查询最低最高提现金额
  105. /*$min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
  106. $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
  107. if ($money < $min_withdrawal_money) {
  108. $this->error('最低提现金额' . $min_withdrawal_money . '元');
  109. }
  110. if ($money > $max_withdrawal_money) {
  111. $this->error('最高提现金额' . $max_withdrawal_money . '元');
  112. }*/
  113. $data['order_no'] = createUniqueNo('T',$this->auth->id);
  114. $data['user_id'] = $this->auth->id;
  115. // $data['score'] = $money;
  116. $data['score'] = $user_money;
  117. $data['type'] = $type;
  118. $data['realname'] = input('realname','');
  119. $data['banknumber'] = input('banknumber','');
  120. $data['bankname'] = input('bankname','');
  121. $data['createtime'] = time();
  122. $data['status'] = 0;
  123. //开启事务
  124. Db::startTrans();
  125. //添加提现记录
  126. $log_id = Db::name('user_withdraw')->insertGetId($data);
  127. if (!$log_id) {
  128. Db::rollback();
  129. $this->error('申请兑换失败');
  130. }
  131. $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$data['score'],2,'积分兑换','user_withdraw',$log_id);
  132. if ($rs_wallet['status'] == false) {
  133. $this->error($rs_wallet['msg']);
  134. Db::rollback();
  135. }
  136. Db::commit();
  137. $this->success('申请兑换成功,请等待审核');
  138. }
  139. //用户钱包流水
  140. public function scorelog(){
  141. $list = Db::name('user_score_log')->field('id,change_value,log_type,createtime')->where('user_id',$this->auth->id)->autopage()->order('id desc')->select();
  142. foreach($list as $key => &$val){
  143. $val['log_type_text'] = model('wallet')->getlogtype($val['log_type']);
  144. }
  145. $this->success('success',$list);
  146. }
  147. }