Intro.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 分销
  7. */
  8. class Intro extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. public function __construct(){
  13. parent::__construct();
  14. }
  15. //首页
  16. public function index(){
  17. $wallet = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  18. }
  19. //我邀请的人列表
  20. public function myintro_list(){
  21. $list = Db::name('user')->field('id,nickname,avatar,createtime')->where('intro_uid',$this->auth->id)->autopage()->select();
  22. $list = list_domain_image($list,['avatar']);
  23. $this->success('success',$list);
  24. }
  25. //提现配置
  26. public function take_cash_config(){
  27. $plat_bilv = config('site.intro_takecash_plat_bili');
  28. $take_cash_days = config('site.intro_takecash_days');
  29. $take_cash_days_str = implode(',',$take_cash_days);
  30. $data = [
  31. 'intromoney' => model('wallet')->getwallet($this->auth->id,'intromoney'),
  32. 'plat_bilv' => $plat_bilv,
  33. 'user_bank' => Db::name('user_bank')->where('user_id',$this->auth->id)->find(),
  34. 'take_cash_days' => $take_cash_days_str,
  35. 'remark' => '每月'.$take_cash_days_str.'日可以提现',
  36. 'take_cash_button' => in_array(date('d'),$take_cash_days) ? 1 : 0,
  37. ];
  38. $this->success('success',$data);
  39. }
  40. //提现before
  41. public function take_cash_before(){
  42. $freemoney = input('freemoney',0);
  43. if(!$freemoney){
  44. $this->error('请填写金额');
  45. }
  46. $money = floatval($freemoney);
  47. if($money<=0)
  48. {
  49. $this->error('金额必须大于0');
  50. }
  51. $min = config('site.intro_takecash_min_money');
  52. $max = config('site.intro_takecash_max_money');
  53. if($money < $min){
  54. $this->error('提现金额不能小于'.$min);
  55. }
  56. if($money > $max){
  57. $this->error('提现金额不能大于'.$max);
  58. }
  59. $user_money = model('wallet')->getwallet($this->auth->id,'intromoney');
  60. if($money > $user_money){
  61. $this->error('提现金额不能大于可提现余额');
  62. }
  63. //平台手续费
  64. $plat_bilv = config('site.intro_takecash_plat_bili');
  65. $plat_money = bcdiv(bcmul($money,$plat_bilv,2),100,2);
  66. //减去手续费,得实得金额
  67. $get_money = bcsub($money,$plat_money,2);
  68. $data = [
  69. 'money' => $money,
  70. 'plat_bilv' => $plat_bilv,
  71. 'plat_money' => $plat_money,
  72. 'get_money' => $get_money,
  73. ];
  74. $this->success(1,$data);
  75. }
  76. //提现
  77. public function take_cash(){
  78. $freemoney = input('freemoney',0);
  79. // $type = input('type',1);
  80. $type = 2;
  81. if(!$freemoney){
  82. $this->error('请填写金额');
  83. }
  84. if (!in_array($type,[1,2,3])) {
  85. $this->error('未知的提现类型');
  86. }
  87. //提现日期限制
  88. $take_cash_days = config('site.intro_takecash_days');
  89. if(!in_array(date('d'),$take_cash_days)){
  90. $take_cash_days_str = implode(',',$take_cash_days);
  91. $this->error('每月'.$take_cash_days_str.'日才可以提现');
  92. }
  93. //赋值money
  94. /*if($rc_id){
  95. $recharge_config = Db::name('take_cash_config')->where('id',$rc_id)->find();
  96. $money = $recharge_config['money'] ?: 0;
  97. }*/
  98. //自由输入覆盖
  99. if(!empty($freemoney)){
  100. $rc_id = 0;
  101. $money = floatval($freemoney);
  102. }
  103. //
  104. if($money<=0)
  105. {
  106. $this->error('金额必须大于0');
  107. }
  108. $min = config('site.intro_takecash_min_money');
  109. $max = config('site.intro_takecash_max_money');
  110. if($money < $min){
  111. $this->error('提现金额不能小于'.$min);
  112. }
  113. if($money > $max){
  114. $this->error('提现金额不能大于'.$max);
  115. }
  116. $check = Db::name('intro_user_take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  117. if($check){
  118. $this->error('您已经申请了提现,请等待审核');
  119. }
  120. $user_money = model('wallet')->getwallet($this->auth->id,'intromoney');
  121. if($money > $user_money){
  122. $this->error('提现金额不能大于可提现余额');
  123. }
  124. if($type == 1){
  125. $table_name = 'user_alipay';
  126. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  127. if(empty($account_json)){
  128. $this->error('未绑定对应的提现账号');
  129. }
  130. }elseif($type == 2){
  131. $table_name = 'user_bank';
  132. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  133. if(empty($account_json)){
  134. $this->error('未绑定对应的提现账号');
  135. }
  136. }elseif($type == 3){
  137. //微信支付
  138. $table_name = 'user_wechat';
  139. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  140. if(empty($account_json)){
  141. $this->error('未绑定对应的提现账号');
  142. }
  143. }
  144. //平台手续费
  145. $plat_bilv = config('site.intro_takecash_plat_bili');
  146. $plat_money = bcdiv(bcmul($money,$plat_bilv,2),100,2);
  147. //减去手续费,得实得金额
  148. $get_money = bcsub($money,$plat_money,2);
  149. $data = [
  150. 'user_id' => $this->auth->id,
  151. 'money' => $money,
  152. 'plat_bilv' => $plat_bilv,
  153. 'plat_money' => $plat_money,
  154. 'get_money' => $get_money,
  155. 'type' => $type,
  156. 'acount_json' => json_encode($account_json),
  157. 'createtime' => time(),
  158. 'updatetime' => time(),
  159. 'status' => 0,
  160. ];
  161. Db::startTrans();
  162. $log_id = Db::name('intro_user_take_cash')->insertGetId($data);
  163. if(!$log_id){
  164. Db::rollback();
  165. $this->error('提现失败');
  166. }
  167. //扣除money
  168. $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'intromoney',-$money,121,'提现(审核中)','intro_user_take_cash',$log_id);
  169. if($rs_wallet['status']===false)
  170. {
  171. Db::rollback();
  172. $this->error($rs_wallet['msg']);
  173. }
  174. Db::commit();
  175. $this->success('申请成功请等待审核');
  176. }
  177. //提现记录
  178. public function take_cash_log(){
  179. $list = Db::name('intro_user_take_cash')->field('id,money,get_money,type,createtime,status')->where(['user_id'=>$this->auth->id])->autopage()->select();
  180. foreach($list as $key => &$val){
  181. $val['remark'] = '';
  182. if($val['type'] == 1){
  183. $val['remark'] = '支付宝提现';
  184. }elseif($val['type'] == 2){
  185. $val['remark'] = '银行卡提现';
  186. }else{
  187. $val['remark'] = '微信提现';
  188. }
  189. }
  190. $this->success('success',$list);
  191. }
  192. }