IndexController.php 8.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: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
//use cmf\controller\HomeBaseController;
use api\portal\model\OrderModel;
use app\portal\model\MemberModel;
use app\portal\model\UserModel;
use app\portal\service\PostService;
use think\Db;
use think\Request;
use think\Loader;
use traits\controller\Jump;
/**
 * @title 用户接口
 * @description 接口说明
 * @group 接口分组
 */

class IndexController extends CommonController
{
    public function index()
    {
//        $return = $this->wxpay(['order_sn'=>201807211101],'保证金支付');
//        $qrcode_url = url('portal/Index/qrcode',['data'=>urlencode($return['code_url'])],true,true);
//        echo '<img src="'.$qrcode_url.'" alt=""/>';
//        $back = [
//            'return'=>$return,
//            'code_url'=>base64_encode($return['code_url']),
//            'qrcode'=> '<img src="'.$qrcode_url.'" alt=""/>',
//            'alipay_url'=>url('portal/Alipay/alipay',array('order_sn'=>201807211101,'name'=>'保证金支付','price'=>0.01))
//        ];
//        $this->redirect($back['alipay_url']);

        $alipay_url = url('portal/Alipay/refund',array('trade_no'=>'2018072421001004410576233593','refund_amount'=>0.01,'refund_reason'=>'中介报价少于3人退款'));
        $this->redirect($alipay_url);

//        echo "<pre/>";
//        print_r('7777');
//        die;
////        合作企业
//        $where_coo['status'] = 1;
//        $final['coop'] = Db::name('Cooperation')->where($where_coo)->order("score desc , create_time desc")->field('pic')->select()->toArray();




        return $this->fetch(':index');
    }

    public function wap_index()
    {
//        $return = $this->wxpay(['order_sn'=>201807211032],'保证金支付');
//        $qrcode_url = url('portal/Index/qrcode',['data'=>urlencode($return['code_url'])],true,true);
//        echo '<img src="'.$qrcode_url.'" alt=""/>';
        $back = [
//            'return'=>$return,
//            'code_url'=>base64_encode($return['code_url']),
//            'qrcode'=> '<img src="'.$qrcode_url.'" alt=""/>',
            'alipay_url'=>url('portal/AlipayWap/alipay',array('order_sn'=>201807211100,'name'=>'保证金支付','price'=>0.01))
        ];
        $this->redirect($back['alipay_url']);

//        echo "<pre/>";
//        print_r('7777');
//        die;
////        合作企业
//        $where_coo['status'] = 1;
//        $final['coop'] = Db::name('Cooperation')->where($where_coo)->order("score desc , create_time desc")->field('pic')->select()->toArray();




        return $this->fetch(':index');
    }

    // 微信h5支付(测试)
    public function wxpayh5() {
        require_once VENDOR_PATH.'WxpayAPI/WxpayH5.php';
        $h5 = new \WxpayH5('wxf69d1d87d173c899','1507884301','VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI','201807211465',
            '保证金支付','1','{"h5_info": {"type":"Wap","wap_url": "http://houseprice.w.bronet.cn","wap_name": "保证金支付"}}' );
        $result = $h5->pay();
        var_dump($result);
        $mweb_url = '';
        if(!empty($result['mweb_url'])) {
            $mweb_url = $result['mweb_url'];
        }
        $this->assign('mwen_url',$mweb_url);
        return $this->fetch(':h5');
    }

    /**
     * 微信h5支付(接口)
     * @param user_id 用户ID
     * @param order_sn 订单号
     * @param _type 支付类型 1,发布需求(保证金);2,中介报价;3,透视卡
     */
    public function wxpay_web() {
        if($this->request->isPost()) {
            $data = $this->request->param();
            $order_model = new OrderModel();
            $orderInfo = $order_model->where(['order_sn'=>$data['order_sn'],'type'=>$data['_type']])->find();
            if(empty($orderInfo['status']) || $orderInfo['status'] > 1) {
                $this->apiResponse(0,'订单已失效');
            }
            $type = [
                1 => '保证金支付',
                2 => '中介报价',
                3 => '透视卡'
            ];
            $scene_info = "{'h5_info': {'type':'Wap','wap_url': 'http://houseprice.w.bronet.cn','wap_name': ".$type[$data["_type"]]."}}";
            require_once VENDOR_PATH.'WxpayAPI/WxpayH5.php';
//            $h5 = new \WxpayH5(config('APP_ID'),config('MCH_ID'),config('WXPAY_KEY'),$data['order_sn'],
//                $type[$data['_type']],'1',$scene_info);
            $h5 = new \WxpayH5('wxf69d1d87d173c899','1507884301','VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI',$data['order_sn'],
                $type[$data['_type']],'1',$scene_info);
            $result = $h5->pay();
            if(empty($result['mweb_url'])) {
                $this->apiResponse(0,'生成失败');
            }
            $return = [
                'mwen_url' => $result['mweb_url'],
                'create_time' => time(),
                'over_time'=>time()+5*60
            ];
            $this->apiResponse(1,'成功',$return);
        }
    }

    // 微信退款(测试)
    public function wxrefund() {
        require_once VENDOR_PATH.'WxpayAPI/WxRefund.php';
        $refund = new \WxRefund('wxf69d1d87d173c899','1507884301','VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI','4200000146201807232084354569',
            '201807250936','1','1','中介报价少于3人退款');
        $result = $refund->pay();
        var_dump($result);
    }

    public function callback() {
        echo 111;
    }


//    登录,注册
//tel 手机号
//password  密码
//sure_password  确认密码
//name 真实姓名


    public function login(Request $request)
    {
        if($request->Post()){
//            验证
            $validate = Loader::validate('User');
            if(!$validate->scene('add')->check($_POST)){
                return json(array('code'=>0,'msg'=>$validate->getError()));
            }
//            密码
            $_POST['password'] = $this->md5($_POST['password']);
//            确认密码
            if($_POST['password'] != $_POST['sure_password']){
                $this->apiResponse('0','两次密码不一致');
            }
//            短信验证码(未完)

//            判断手机号是否已注册
            $user = new MemberModel($_POST);
            $where_user['tel'] = $_POST['tel'];
            $is_isset = $user->where($where_user)->find();
            if($is_isset){
                $this->apiResponse('0','您已注册过,请直接登录');
            }
            $add = $user->allowField(true)->save();
            if($add){
                echo "<pre/>";
                print_r('1');
                die;
            }else{
                echo "<pre/>";
                print_r('2');
                die;
            }

        }else{
//            服务协议
            $service = new PostService();
            $list = $service->publishedArticle(1,1)->toArray();
//              推荐人(未完)


            if($list){
                $this->apiResponse('1','成功',$list);
            }else{
                $this->apiResponse('0','暂无内容');
            }

        }
    }

    // 微信支付二维码
    public function qrcode() {
        $data = $this->request->param('data');
        require_once VENDOR_PATH.'WxpayAPI/example/phpqrcode/phpqrcode.php';
        $url = urldecode($data);
        \QRcode::png($url);
    }

    // 检测微信支付是否完成
    public function checkStatus() {
        if($this->request->isAjax()) {
            $order_sn = $this->request->param('order_sn');
            $order_model = new OrderModel();
            $status = $order_model->where(['order_sn'=>$order_sn])->value('status');
            if(empty($status)) {
                $this->apiResponse(0,'订单不存在');
            }
            if($status == 1 || $status == 9) {
                $this->apiResponse(0,'未支付成功');
            }
            if($status == 2) {
                $this->apiResponse(1,'支付成功');
            }
        }
    }


}