Balancepay.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\admin\controller\base\pay;
  3. /**
  4. * @title 余额支付控制器
  5. * @desc
  6. * @author Rock
  7. * @version 1.0
  8. * @icon fa fa-cny
  9. */
  10. class Balancepay extends Confirmpay
  11. {
  12. protected $noNeedToken = [];
  13. protected $payrecordModel = null;
  14. protected $orderModel = null;
  15. protected $memberbalanceModel = null;
  16. protected $safetyorderModel = null;
  17. protected $companycourseorderModel = null;
  18. protected $resitorderModel = null;
  19. protected $paytype = 4;//余额支付
  20. public function initialize()
  21. {
  22. parent::initialize();
  23. $this->payrecordModel = new \app\common\model\pay\Payrecord;
  24. $this->orderModel = new \app\common\model\order\Courseorder;
  25. $this->memberbalanceModel = new \app\common\model\member\Balance;
  26. $this->safetyorderModel = new \app\common\model\order\Safetyorder;
  27. $this->companycourseorderModel = new \app\common\model\order\Companycourseorder;
  28. $this->resitorderModel = new \app\common\model\order\Resitorder;
  29. $this->ptypeList = $this->payrecordModel->getPtypeList();
  30. }
  31. /**
  32. * @title 创建支付流水并统一下单
  33. * @desc 说明
  34. * @method GET/POST
  35. * @param {string} {oid} {} {订单号}
  36. * @param {int} {ptype} {0} {订单类型:1=课程订单,2=余额充值,3=企业安全教育,4=企业批量购买课程,5=补考缴费}
  37. * @return {type} {name} {default} {desc}
  38. * @author Rock
  39. */
  40. public function pay($oid="",$ptype=0)
  41. {
  42. if(empty($oid))ShowJson(1,"缺少必要参数");
  43. if(empty($ptype))ShowJson(1,"缺少必要参数");
  44. $uid=$this->Userinfo->uid;//获取用户ID
  45. $poid = CreateOrderID();
  46. $ptypeText = !empty($this->ptyleList[$ptype])?$this->ptyleList[$ptype]:"";
  47. if($ptype==1){//课程订单支付
  48. $where = [];
  49. $where['oid'] = ['=',$oid];
  50. $where['status'] = ['=',1];
  51. $orderInfo = $this->orderModel->where($where)->find();
  52. if(empty($orderInfo))ShowJson(1,"没有找到待支付订单");
  53. $amount = $orderInfo->pay_amount;
  54. $msg = "购买订单".$oid."支付";
  55. }elseif($ptype==2){//余额充值
  56. ShowJson(1,"余额充值不能使用余额支付");
  57. }elseif($ptype==3){//企业安全教育课程支付
  58. $where = [];
  59. $where['oid'] = ['=',$oid];
  60. $where['status'] = ['=',1];
  61. $orderInfo = $this->safetyorderModel->where($where)->find();
  62. if(empty($orderInfo))ShowJson(1,"没有找到待支付订单");
  63. $amount = $orderInfo->pay_amount;
  64. $msg = "企业安全教育订单".$oid."支付";
  65. }elseif($ptype==4){
  66. $where = [];
  67. $where['oid'] = ['=',$oid];
  68. $where['status'] = ['=',1];
  69. $orderInfo = $this->companycourseorderModel->where($where)->find();
  70. $amount = $orderInfo->pay_amount;
  71. $msg = "企业批量购买课程订单".$oid."支付";
  72. }elseif($ptype==5){
  73. $where = [];
  74. $where['oid'] = ['=',$oid];
  75. $where['status'] = ['=',1];
  76. $orderInfo = $this->resitorderModel->where($where)->find();
  77. $amount = $orderInfo->pay_amount;
  78. $msg = "补考缴费订单".$oid."支付";
  79. }
  80. //创建支付订单
  81. $insertData = [
  82. 'oid' => $oid,
  83. 'uid' => $this->Userinfo->uid,
  84. 'type' => $this->paytype,
  85. 'msg' => $msg,
  86. 'amount'=> $amount,
  87. 'status'=> 0,
  88. 'ptype' => $ptype,
  89. 'poid' => $poid
  90. ];
  91. if(empty($insertData['amount'])){
  92. ShowJson(1,"支付金额小于0.01元");
  93. }
  94. $this->payrecordModel->create($insertData);
  95. if($this->memberbalanceModel->reduce($uid,$amount,$msg)){//余额扣除成功后
  96. if($this->ConfirmPay($poid)){
  97. ShowJson(0,"余额支付成功");
  98. }else{
  99. ShowJson(1,"余额支付失败");
  100. }
  101. }else{
  102. ShowJson(1,'余额支付失败,余额不足');
  103. }
  104. }
  105. //模拟充值
  106. public function increase()
  107. {
  108. $amount = input('amount');
  109. $res = $this->memberbalanceModel->increase($this->Userinfo->uid,$amount,"余额充值");
  110. if($res){
  111. ShowJson(0,'成功充值'.$amount.'元');
  112. }else{
  113. ShowJson(1,'充值'.$amount.'元失败');
  114. }
  115. }
  116. }