Money.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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' => 1,
  18. 'max_withdrawal_money' => 50000,
  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. //检查其他申请
  36. $check = Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('status',0)->find();
  37. if($check){
  38. $this->error('目前还有兑换在审核中,请稍后在兑换');
  39. }
  40. //检查是否未确认收货
  41. $map2 = [
  42. 'user_id' => $this->auth->id,
  43. 'status' => 1,
  44. 'have_paid' => ['gt',0],
  45. 'have_received' => 0,
  46. ];
  47. $check2 = Db::name('unishop_order')->where($map2)->find();
  48. if($check2){
  49. if($check2['have_delivered'] == 0){
  50. $this->error('您有订单尚未发货,请等待订单完成');
  51. }
  52. $this->error('您有订单尚未确认收货,请先完成收货');
  53. }
  54. //开启事务
  55. Db::startTrans();
  56. //余额查询
  57. if($from == 'all'){
  58. $user_money = model('wallet')->getWallet($this->auth->id,'score');
  59. }else{
  60. $user_money = model('wallet')->getWallet($this->auth->id,'shouyi');
  61. }
  62. if ($user_money <= 0) {
  63. Db::rollback();
  64. $this->error('积分不足');
  65. }
  66. $data = [];
  67. $data['order_no'] = createUniqueNo('T',$this->auth->id);
  68. $data['user_id'] = $this->auth->id;
  69. $data['score'] = $user_money;
  70. $data['type'] = $type;
  71. $data['realname'] = input('realname','');
  72. $data['banknumber'] = input('banknumber','');
  73. $data['bankname'] = input('bankname','');
  74. $data['createtime'] = time();
  75. $data['status'] = 0;
  76. $data['from'] = ($from == 'all') ? 1 : 2; //all=1,bufen=2
  77. //添加提现记录
  78. $log_id = Db::name('user_withdraw')->insertGetId($data);
  79. if (!$log_id) {
  80. Db::rollback();
  81. $this->error('申请兑换失败');
  82. }
  83. //扣收益
  84. if($from == 'bufen'){
  85. $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'shouyi',-$data['score'],2,'积分兑换','user_withdraw',$log_id);
  86. if ($rs_wallet['status'] == false) {
  87. $this->error($rs_wallet['msg']);
  88. Db::rollback();
  89. }
  90. }
  91. //扣积分
  92. $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$data['score'],2,'积分兑换','user_withdraw',$log_id);
  93. if ($rs_wallet['status'] == false) {
  94. $this->error($rs_wallet['msg']);
  95. Db::rollback();
  96. }
  97. Db::commit();
  98. $this->success('申请兑换成功,请等待审核');
  99. }
  100. //废弃的提现
  101. public function old_scorewithdraw() {
  102. $type = input('type', 0, 'intval'); //类型:1=支付宝,2=微信,3=银行
  103. /*$money = input('score', '', 'intval');
  104. if ($money <= 0) {
  105. $this->error('请输入正确兑换积分');
  106. }*/
  107. $check = Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('status',0)->find();
  108. if($check){
  109. $this->error('目前还有兑换在审核中,请稍后在兑换');
  110. }
  111. //余额查询
  112. $user_money = model('wallet')->getWallet($this->auth->id,'score');
  113. /*if ($user_money < $money) {
  114. $this->error('余额不足');
  115. }*/
  116. if ($user_money <= 0) {
  117. $this->error('积分不足');
  118. }
  119. //查询最低最高提现金额
  120. /*$min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
  121. $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
  122. if ($money < $min_withdrawal_money) {
  123. $this->error('最低提现金额' . $min_withdrawal_money . '元');
  124. }
  125. if ($money > $max_withdrawal_money) {
  126. $this->error('最高提现金额' . $max_withdrawal_money . '元');
  127. }*/
  128. $data['order_no'] = createUniqueNo('T',$this->auth->id);
  129. $data['user_id'] = $this->auth->id;
  130. // $data['score'] = $money;
  131. $data['score'] = $user_money;
  132. $data['type'] = $type;
  133. $data['realname'] = input('realname','');
  134. $data['banknumber'] = input('banknumber','');
  135. $data['bankname'] = input('bankname','');
  136. $data['createtime'] = time();
  137. $data['status'] = 0;
  138. //开启事务
  139. Db::startTrans();
  140. //添加提现记录
  141. $log_id = Db::name('user_withdraw')->insertGetId($data);
  142. if (!$log_id) {
  143. Db::rollback();
  144. $this->error('申请兑换失败');
  145. }
  146. $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$data['score'],2,'积分兑换','user_withdraw',$log_id);
  147. if ($rs_wallet['status'] == false) {
  148. $this->error($rs_wallet['msg']);
  149. Db::rollback();
  150. }
  151. Db::commit();
  152. $this->success('申请兑换成功,请等待审核');
  153. }
  154. //用户钱包流水
  155. public function scorelog(){
  156. $list = Db::name('user_score_log')->field('id,change_value,log_type,createtime')->where('user_id',$this->auth->id)->autopage()->order('id desc')->select();
  157. foreach($list as $key => &$val){
  158. $val['log_type_text'] = model('wallet')->getlogtype($val['log_type']);
  159. }
  160. $this->success('success',$list);
  161. }
  162. }