PayView.php 2.2 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/29
 * Time: 9:12
 */

namespace app\admin\controller;

use app\common\controller\Backend;
use fast\Random;
use think\Db;

class PayView extends Backend
{
    public function test(){
        dump(cache('nnn'));
        dump(cache('successful'));
    }
    public function index(){
        //商户信息
        $admin = Db::name('admin')->where(['id'=>$this->auth->id])->find();
        //红包券充值比例
        $exp_ratio = Db::name('exp_ratio')->where(['id'=>1])->find();
        $this->assign('exp_ratio',$exp_ratio);
        $this->assign('admin',$admin);
        return $this->fetch();
    }
    public function create_order(){
        $admin_id = $this->request->param('admin_id',0,'intval');
        $total = $this->request->param('total',0,'intval');
        if(empty($admin_id) || empty($total)){
            $this->error('缺少必要参数');
        }
        //红包券充值比例
        $exp_ratio = Db::name('exp_ratio')->where(['id'=>1])->find();
        $admin = Db::name('admin')->where(['id'=>$admin_id])->find();
        $arr['num'] = date("YmdHis") . Random::alnum(6);
        $arr['admin_id'] = $admin_id;
        $arr['user_id'] = $admin['user_id'];
        $arr['total'] = $total;
        $arr['money'] = $exp_ratio['ratio']/0.01*$total;//$total*$exp_ratio['ratio']*0.01;
        $arr['create_time'] = time();
        $arr['status'] = 1;
        $order_id = Db::name('order')->insertGetId($arr);
        $this->success('','',['order_id'=>$order_id]);
    }
    public function pay(){
        $order_id = $this->request->param('order_id',0,'intval');
        $data = Db::name('order')->where(['id'=>$order_id])->find();
        $pay = new Pay();
        $code_url = $pay->index($data);
        if(empty($code_url)){
            $this->error('生成二维码失败');
        }
        \PHPQRCode\QRcode::png($code_url);
    }
    public function order_pay(){
        $order_id = $this->request->param('order_id',0,'intval');
        $data = Db::name('order')->where(['id'=>$order_id])->find();
        if($data['status'] != 2){
            $this->error('');
        }
        $this->success();
    }
}