123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\admin\controller\base\pay;
- /**
- * @title 余额支付控制器
- * @desc
- * @author Rock
- * @version 1.0
- * @icon fa fa-cny
- */
- class Balancepay extends Confirmpay
- {
- protected $noNeedToken = [];
- protected $payrecordModel = null;
- protected $orderModel = null;
- protected $memberbalanceModel = null;
- protected $safetyorderModel = null;
- protected $companycourseorderModel = null;
- protected $resitorderModel = null;
- protected $paytype = 4;//余额支付
- public function initialize()
- {
- parent::initialize();
- $this->payrecordModel = new \app\common\model\pay\Payrecord;
- $this->orderModel = new \app\common\model\order\Courseorder;
- $this->memberbalanceModel = new \app\common\model\member\Balance;
- $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,"缺少必要参数");
- $uid=$this->Userinfo->uid;//获取用户ID
- $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){//余额充值
- ShowJson(1,"余额充值不能使用余额支付");
- }elseif($ptype==3){//企业安全教育课程支付
- $where = [];
- $where['oid'] = ['=',$oid];
- $where['status'] = ['=',1];
- $orderInfo = $this->safetyorderModel->where($where)->find();
- if(empty($orderInfo))ShowJson(1,"没有找到待支付订单");
- $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' => $this->Userinfo->uid,
- 'type' => $this->paytype,
- 'msg' => $msg,
- 'amount'=> $amount,
- 'status'=> 0,
- 'ptype' => $ptype,
- 'poid' => $poid
- ];
- if(empty($insertData['amount'])){
- ShowJson(1,"支付金额小于0.01元");
- }
- $this->payrecordModel->create($insertData);
- if($this->memberbalanceModel->reduce($uid,$amount,$msg)){//余额扣除成功后
- if($this->ConfirmPay($poid)){
- ShowJson(0,"余额支付成功");
- }else{
- ShowJson(1,"余额支付失败");
- }
- }else{
- ShowJson(1,'余额支付失败,余额不足');
- }
- }
- //模拟充值
- public function increase()
- {
- $amount = input('amount');
- $res = $this->memberbalanceModel->increase($this->Userinfo->uid,$amount,"余额充值");
- if($res){
- ShowJson(0,'成功充值'.$amount.'元');
- }else{
- ShowJson(1,'充值'.$amount.'元失败');
- }
- }
- }
|