model = new \app\extend\weixin\Wxpay; $this->payrecordModel = new \app\common\model\pay\Payrecord; $this->orderModel = new \app\common\model\order\Courseorder; $this->balanceorderModel = new \app\common\model\order\Balanceorder; $this->safetyorderModel = new \app\common\model\order\Safetyorder; $this->companycourseorderModel = new \app\common\model\order\Companycourseorder; $this->resitorderModel = new \app\common\model\order\Resitorder; $this->ptypeList = $this->payrecordModel->getPtypeList(); } /** * @title 创建支付流水并统一下单 * @desc 说明 * @method GET/POST * @param {string} {oid} {} {订单号} * @param {int} {ptype} {0} {订单类型:1=课程订单,2=余额充值,3=企业安全教育,4=企业批量购买课程,5=补考缴费} * @return {type} {name} {default} {desc} * @author Rock */ public function pay($oid="",$ptype=0) { if(empty($oid))ShowJson(1,"缺少必要参数"); if(empty($ptype))ShowJson(1,"缺少必要参数"); $poid = CreateOrderID(); $ptypeText = !empty($this->ptyleList[$ptype])?$this->ptyleList[$ptype]:""; if($ptype==1){//课程订单支付 $where = []; $where['oid'] = ['=',$oid]; $where['status'] = ['=',1]; $orderInfo = $this->orderModel->where($where)->find(); if(empty($orderInfo))ShowJson(1,"没有找到待支付订单"); $amount = $orderInfo->pay_amount; $msg = "购买订单".$oid."支付"; }elseif($ptype==2){//余额充值 $where = []; $where['oid'] = ['=',$oid]; $where['status'] = ['=',1]; $orderInfo = $this->balanceorderModel->where($where)->find(); $amount = $orderInfo->pay_amount; $msg = "充值订单".$oid."支付"; }elseif($ptype==3){//企业安全教育课程 $where = []; $where['oid'] = ['=',$oid]; $where['status'] = ['=',1]; $orderInfo = $this->safetyorderModel->where($where)->find(); $amount = $orderInfo->pay_amount; $msg = "企业安全教育订单".$oid."支付"; }elseif($ptype==4){ $where = []; $where['oid'] = ['=',$oid]; $where['status'] = ['=',1]; $orderInfo = $this->companycourseorderModel->where($where)->find(); $amount = $orderInfo->pay_amount; $msg = "企业批量购买课程订单".$oid."支付"; }elseif($ptype==5){ $where = []; $where['oid'] = ['=',$oid]; $where['status'] = ['=',1]; $orderInfo = $this->resitorderModel->where($where)->find(); $amount = $orderInfo->pay_amount; $msg = "补考缴费订单".$oid."支付"; } //创建支付订单 $insertData = [ 'oid' => $oid, 'uid' => $orderInfo->uid, 'type' => $this->paytype, 'msg' => $msg, 'amount'=> $amount, 'status'=> 0, 'ptype' => $ptype, 'poid' => $poid ]; if(empty($insertData['amount'])){ ShowJson(1,"支付金额小于0.01元"); } $res = $this->payrecordModel->create($insertData); //调用微信支付统一下单接口,返回供小程序端支付需要的参数 $data = $this->model->NativePay($poid,$amount,$ptypeText."订单".$oid."支付"); ShowJson(0,'支付请求已发起',$data); } }