123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- class Intro extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- protected $wallet = [];
- public function __construct(){
- parent::__construct();
- $this->wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
- }
-
- public function index(){
- $result = [
- 'user_id' => $this->auth->id,
- 'nickname' => $this->auth->nickname,
- 'avatar' => localpath_to_netpath($this->auth->avatar),
- 'intro_level' => $this->wallet['intro_level'],
- ];
-
- $result['leijiyongjin'] = Db::name('user_intromoney_log')->where('user_id',$this->auth->id)->where('log_type','IN',[101,102,111])->sum('change_value');
-
- $zhitui_ids = Db::name('user_wallet')->where('intro_uid',$this->auth->id)->column('user_id');
- $jiantui_ids = Db::name('user_wallet')->where('intro_uid','IN',$zhitui_ids)->column('user_id');
- $result['xiaxianzongshu'] = count($zhitui_ids) + count($jiantui_ids);
-
- $result['ketixian'] = $this->wallet['intromoney'];
-
- $result['dairuzhang'] = 0;
-
- $result['tixianzhong'] = Db::name('intro_user_take_cash')->where('user_id',$this->auth->id)->where('status',0)->sum('money');
-
- $result['yitixian'] = Db::name('intro_user_take_cash')->where('user_id',$this->auth->id)->where('status',1)->sum('money');
-
- $list = $this->get_my_down_list();
- $down_uids = array_column($list,'user_id');
-
- $list2 = $this->get_my_downdown_list($down_uids);
- $down_down_uids = array_column($list2,'user_id');
-
- $tuandui_ids = array_merge($down_uids,$down_down_uids);
-
- $result['wodetuandui'] = count($tuandui_ids);
-
- $result['yaoqinghaoyou'] = count($down_uids);
-
- $result['fenxiaodingdan'] = Db::name('pay_order')->where('user_id','IN',$tuandui_ids)->where('table_name','money_recharge')->where('order_status',1)->count();
-
- $this->success('success',$result);
- }
-
- private function get_my_down_list(){
- $chuju = config('site.intro_chuju_min_money');
-
- $list = Db::name('user_wallet')->alias('uw')
- ->field('uw.user_id,uw.money,uw.intro_level,uw.intro_uid')
- ->where('uw.intro_uid',$this->auth->id)
- ->where('uw.intro_level','neq','-1')
- ->where('uw.intro_level','elt',$this->wallet['intro_level'])
- ->where('uw.money','lt',$chuju)
- ->select();
- return !empty($list) ? $list : [];
- }
-
- private function get_my_downdown_list($down_uids = false){
- if($down_uids === false){
- $list = $this->get_my_down_list();
- $down_uids = array_column($list,'user_id');
- }
- $chuju = config('site.intro_chuju_min_money');
-
- $list2 = Db::name('user_wallet')->alias('uw')
- ->field('uw.user_id,uw.money,uw.intro_level,uw.intro_uid')
- ->join('user_wallet intro','uw.intro_uid = intro.user_id','LEFT')
- ->whereIN('uw.intro_uid',$down_uids)
- ->where('uw.intro_level','neq','-1')
- ->where('uw.money','lt',$chuju)
- ->where('uw.intro_level','elt',$this->wallet['intro_level'])
- ->where('uw.intro_level <= intro.intro_level')
- ->select();
- return !empty($list2) ? $list2 : [];
- }
-
- public function my_intromoney_log(){
- $type = input('type',0);
- $map = [
- 'user_id' => $this->auth->id,
- ];
- if($type == 1){
- $map['change_value'] = ['gt',0];
- }
- if($type == 2){
- $map['change_value'] = ['lt',0];
- }
- $list = Db::name('user_intromoney_log')
- ->field('id,log_type,before,change_value,remain,remark,createtime')
- ->where($map)->order('id desc')->autopage()->select();
- $this->success('success',$list);
- }
-
- public function take_cash_config(){
- $plat_bilv = config('site.intro_takecash_plat_bili');
- $take_cash_days = config('site.intro_takecash_days');
- $take_cash_days_str = implode(',',$take_cash_days);
- $data = [
- 'intromoney' => model('wallet')->getwallet($this->auth->id,'intromoney'),
- 'plat_bilv' => $plat_bilv,
- 'user_bank' => Db::name('user_bank')->where('user_id',$this->auth->id)->find(),
- 'take_cash_days' => $take_cash_days_str,
- 'remark' => '每月'.$take_cash_days_str.'日可以提现',
- 'take_cash_button' => in_array(date('d'),$take_cash_days) ? 1 : 0,
- ];
- $this->success('success',$data);
- }
-
- public function take_cash_before(){
- $freemoney = input('freemoney',0);
- if(!$freemoney){
- $this->error('请填写金额');
- }
- $money = floatval($freemoney);
- if($money<=0)
- {
- $this->error('金额必须大于0');
- }
- $min = config('site.intro_takecash_min_money');
- $max = config('site.intro_takecash_max_money');
- if($money < $min){
- $this->error('提现金额不能小于'.$min);
- }
- if($money > $max){
- $this->error('提现金额不能大于'.$max);
- }
- $user_money = model('wallet')->getwallet($this->auth->id,'intromoney');
- if($money > $user_money){
- $this->error('提现金额不能大于可提现余额');
- }
-
- $plat_bilv = config('site.intro_takecash_plat_bili');
- $plat_money = bcdiv(bcmul($money,$plat_bilv,2),100,2);
-
- $get_money = bcsub($money,$plat_money,2);
- $data = [
- 'money' => $money,
- 'plat_bilv' => $plat_bilv,
- 'plat_money' => $plat_money,
- 'get_money' => $get_money,
- ];
- $this->success(1,$data);
- }
-
- public function take_cash(){
- $freemoney = input('freemoney',0);
- $type = 2;
- if(!$freemoney){
- $this->error('请填写金额');
- }
- if (!in_array($type,[1,2,3])) {
- $this->error('未知的提现类型');
- }
-
- $take_cash_days = config('site.intro_takecash_days');
- if(!in_array(date('d'),$take_cash_days)){
- $take_cash_days_str = implode(',',$take_cash_days);
- $this->error('每月'.$take_cash_days_str.'日才可以提现');
- }
-
-
-
- if(!empty($freemoney)){
- $rc_id = 0;
- $money = floatval($freemoney);
- }
-
- if($money<=0)
- {
- $this->error('金额必须大于0');
- }
- $min = config('site.intro_takecash_min_money');
- $max = config('site.intro_takecash_max_money');
- if($money < $min){
- $this->error('提现金额不能小于'.$min);
- }
- if($money > $max){
- $this->error('提现金额不能大于'.$max);
- }
- $check = Db::name('intro_user_take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
- if($check){
- $this->error('您已经申请了提现,请等待审核');
- }
- $user_money = model('wallet')->getwallet($this->auth->id,'intromoney');
- if($money > $user_money){
- $this->error('提现金额不能大于可提现余额');
- }
- if($type == 1){
- $table_name = 'user_alipay';
- $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
- if(empty($account_json)){
- $this->error('未绑定对应的提现账号');
- }
- }elseif($type == 2){
- $table_name = 'user_bank';
- $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
- if(empty($account_json)){
- $this->error('未绑定对应的提现账号');
- }
- }elseif($type == 3){
-
- $table_name = 'user_wechat';
- $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
- if(empty($account_json)){
- $this->error('未绑定对应的提现账号');
- }
- }
-
- $plat_bilv = config('site.intro_takecash_plat_bili');
- $plat_money = bcdiv(bcmul($money,$plat_bilv,2),100,2);
-
- $get_money = bcsub($money,$plat_money,2);
- $data = [
- 'user_id' => $this->auth->id,
- 'money' => $money,
- 'plat_bilv' => $plat_bilv,
- 'plat_money' => $plat_money,
- 'get_money' => $get_money,
- 'type' => $type,
- 'acount_json' => json_encode($account_json),
- 'createtime' => time(),
- 'updatetime' => time(),
- 'status' => 0,
- ];
- Db::startTrans();
- $log_id = Db::name('intro_user_take_cash')->insertGetId($data);
- if(!$log_id){
- Db::rollback();
- $this->error('提现失败');
- }
-
- $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'intromoney',-$money,121,'提现(审核中)','intro_user_take_cash',$log_id);
- if($rs_wallet['status']===false)
- {
- Db::rollback();
- $this->error($rs_wallet['msg']);
- }
- Db::commit();
- $this->success('申请成功请等待审核');
- }
-
- public function take_cash_log(){
- $list = Db::name('intro_user_take_cash')->field('id,money,get_money,type,createtime,status')->where(['user_id'=>$this->auth->id])->autopage()->select();
- foreach($list as $key => &$val){
- $val['remark'] = '';
- if($val['type'] == 1){
- $val['remark'] = '支付宝提现';
- }elseif($val['type'] == 2){
- $val['remark'] = '银行卡提现';
- }else{
- $val['remark'] = '微信提现';
- }
- }
- $this->success('success',$list);
- }
- }
|