Money.php 7.6 KB

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