GetmoneyController.php 7.3 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\user\controller;

use cmf\controller\AdminBaseController;
use think\Db;
use think\Loader;
use think\Request;

class GetmoneyController extends AdminBaseController
{



//    提现申请
    public function index(){
        $data = $this->request->param();
        $arr = array();
        if($data){
            $startTime = empty($data['start_time']) ? 0 : strtotime($data['start_time']);
            $endTime   = empty($data['end_time']) ? 0 : strtotime($data['end_time']);
            if ($startTime && $endTime) {
                $arr['start_time'] = $data['start_time'];
                $arr['end_time'] = $data['end_time'];
                $where_money['d.create_time'] = array('between',"$startTime,$endTime");
                $this->assign('start_time', $data['start_time']);
                $this->assign('end_time', $data['end_time']);
            }else{
                if($startTime){
                    $arr['start_time'] = $data['start_time'];
                    $where_money['d.create_time'] = array('egt',$startTime);
                    $this->assign('start_time', $data['start_time']);
                }
                if($endTime){
                    $arr['end_time'] = $data['end_time'];
                    $where_money['d.create_time'] = array('elt',$endTime);
                    $this->assign('end_time', $data['end_time']);
                }
            }
            if(!empty($data['name'])){
                $arr['name'] = $data['name'];
                $where_money['name'] = array('like','%'.$data['name'].'%');
                $this->assign('name', $data['name']);
            }
            if(!empty($data['tel'])){
                $arr['tel'] = $data['tel'];
                $where_money['tel'] = array('like','%'.$data['tel'].'%');
                $this->assign('tel', $data['tel']);
            }
        }
//        $where_money['user_id'] = $data['id'];
        $where_money['d.order_type'] = 6;
        $where_money['d.type'] = 3;
        $where_money['d.status'] = array('neq',9);
        $where_money['c.status'] = array('neq',9);
        $money_list = Db::name('MoneyDetail')->alias('d')
            ->join("Member m",'m.id = d.user_id')
            ->join("Card c",'c.user_id = m.id')
            ->join("Bank b",'b.id = c.bank_id')
            ->where($where_money)
            ->field("m.name,m.tel,m.type,d.money,d.status,d.id,d.create_time,c.card_num , b.name as card_name")
            ->order('create_time desc')
            ->paginate(10,false,['query'=>$arr]);
        $page = $money_list->render();
        $this->assign('page',$page);
//        $this->assign('uid',$data['id']);
        $this->assign('lists',$money_list);
        return $this->fetch('getdetail');
    }



//    同意提现
    public function agree(){
        $data = $this->request->param();
        $where_money['id'] = $data['id'];
//        $where_money['user_id'] = $data['uid'];
        $where_money['order_type'] = 6;
        $where_money['type'] = 3;
        $where_money['status'] = array('neq',9);
        $money = Db::name('MoneyDetail')->where($where_money)->find();
        if($money){
            $save['status'] = 3;
            $save['update_time'] = time();
            $update = Db::name('MoneyDetail')->where($where_money)->update($save);
            $where_member['id'] = $money['user_id'];
            $add_g = Db::name('Member')->where($where_member)->setDec('get_money',$money['money']);
            if(!$add_g){
                $this->error('失败');
            }
            if($update){
                $this->success('成功');
            }else{
                $this->error('失败');
            }
        }else{
            $this->error('订单状态不正确');
        }
    }

    //    拒绝提现
    public function refuse(){
        $data = $this->request->param();
        $where_money['id'] = $data['id'];
//        $where_money['user_id'] = $data['uid'];
        $where_money['order_type'] = 6;
        $where_money['type'] = 3;
        $where_money['status'] = array('neq',9);
        $money = Db::name('MoneyDetail')->where($where_money)->find();
        if($money){
            $where_member['id'] = $money['user_id'];
            $up_money['money'] = $money['money'];
            $up_money['get_money'] = $money['money'];
            $add_m = Db::name('Member')->where($where_member)->setInc('money',$money['money']);
            $add_g = Db::name('Member')->where($where_member)->setDec('get_money',$money['money']);
            if(!$add_m && !$add_g){
                $this->error('失败');
            }
            $save['user_id'] = $money['user_id'];
            $save['user_id'] = $money['user_id'];
            $save['user_type'] = $money['user_type'];
            $save['title'] = '提现退回';
            $save['money'] = $money['money'];
            $save['order_type'] = 6;
            $save['type'] = 3;
            $save['pay_type'] = 3;
            $save['status'] = 4;
            $save['create_time'] = time();
            $save['update_time'] = time();
            $update = Db::name('MoneyDetail')->insertGetId($save);
            $next_save['title'] = '余额提现';
            $next_save['update_time'] = time();
            $next_save['status'] = 6;
            $save_update = Db::name('MoneyDetail')->where($where_money)->update($next_save);
            if($update && $save_update){
                $this->success('成功');
            }else{
                $this->error('失败');
            }
        }else{
            $this->error('订单状态不正确');
        }
    }


//    提现
    public function getmoney(){
        $data = $this->request->param();
        $where_member['id'] = $data['id'];
        $member = Db::name('Member')->where($where_member)->field('id,name,tel')->find();
        if($member){
            $where_money['user_id'] = $member['id'];
            $where_money['user_type'] = 1;
            $where_money['order_type'] = 6;
            $detail = Db::name('MoneyDetail')->where($where_money)->select()->toArray();
            $this->assign('lists',$detail);
        }else{
            $this->error('用户信息获取失败');
        }
    }


    /**
     * 后台删除第三方用户绑定
     * @adminMenu(
     *     'name'   => '删除第三方用户绑定',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除第三方用户绑定',
     *     'param'  => ''
     * )
     */
    public function delete()
    {
        $id = input('param.id', 0, 'intval');
        if (empty($id)) {
            $this->error('非法数据!');
        }
        Db::name("third_party_user")->where("id", $id)->delete();
        $this->success("删除成功!", "admin_oauth/index");
    }

}