model = new \app\extend\alibaba\AliPay; $this->payrecordModel = new \app\common\model\pay\Payrecord; } /** * @title 创建支付流水并统一下单 * @desc 说明 * @method GET/POST * @param {string} {oid} {} {订单号} * @param {int} {ptype} {0} {订单类型:1=课程订单,2=余额充值,3=企业安全教育,4=企业批量购买课程,5=补考缴费} * @param {string} {client} {page} {客户端:mobile=手机端,page=PC端} * @return {type} {name} {default} {desc} * @author Rock */ public function pay($oid="",$ptype=0,$client="page") { 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($client,$poid,$amount,$ptypeText."订单".$oid."支付"); ShowJson(0,'支付请求已发起',$data); } //支付宝支付回调 public function callback() { $data = $this->request->request(); //支付成功或交易完成 if($data['trade_status']=='TRADE_SUCCESS' || $data['trade_status']=='TRADE_FINISHED'){ WLog('Alipay_Callback','回调校验成功!:'.array2string($data)); $poid = $data['out_trade_no']; $tran_id = $data['trade_no']; if($this->ConfirmPay($poid,$tran_id)){ echo "SUCCESS"; }else{ echo "FAIL"; } }elseif($data['trade_status']=='WAIT_BUYER_PAY'){ WLog('Alipay_Callback',"等待用户支付"); }elseif($data['trade_status']=='TRADE_CLOSED'){ WLog('Alipay_Callback',"交易关闭"); } } }