Money.php 6.4 KB

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