model = new \app\extend\unionpay\Unionpay; $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=补考缴费} * @param {string} {client} {page} {客户端:app=手机端,web=PC端} * @return {type} {name} {default} {desc} * @author Rock */ public function pay($oid="",$ptype=0,$client="web") { 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->pay($poid,$amount,$client); ShowJson(0,'支付请求已发起',$data); } //银联支付回调 public function callback() { $data = $this->request->request(); //支付成功或交易完成 if($this->model->callback_validate($data)){ WLog('Unionpay_Callback','回调校验成功!:'.array2string($result)); $poid = $data['orderId']; $tran_id = $data['queryId']; if($this->ConfirmPay($poid,$tran_id)){ WLog("Unionpay_Callback","支付成功,业务处理成功"); }else{ WLog("Unionpay_Callback","支付成功,业务处理失败"); } } echo "ok"; } }