PxApplyController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace mall\controllers;
  3. use bizHd\custom\classes\CustomClass;
  4. use bizMall\px\classes\PxApplyClass;
  5. use bizMall\px\classes\PxClassClass;
  6. use bizMall\wx\classes\WxOpenClass;
  7. use common\components\dict;
  8. use common\components\httpUtil;
  9. use common\components\util;
  10. use Yii;
  11. use bizMall\promote\services\CouponService;
  12. /**
  13. * 培训报名
  14. */
  15. class PxApplyController extends BaseController
  16. {
  17. //报名申请 ssh 2021.3.17
  18. public function actionAdd()
  19. {
  20. $get = Yii::$app->request->get();
  21. $classId = $get['classId'] ?? 0;
  22. $info = PxClassClass::getClassInfo($classId);
  23. PxClassClass::valid($info, $this->sjId);
  24. $customId = $this->customId;
  25. if (!empty($customId)) {
  26. $custom = CustomClass::getCustomInfo($customId);
  27. CustomClass::valid($custom, $this->sjId);
  28. }
  29. $get['sjId'] = $this->sjId;
  30. $get['prePrice'] = $info['tuition'];
  31. $get['actPrice'] = $info['tuition'];
  32. $get['shopId'] = $this->shopId;
  33. $get['shopAdminId'] = 0;
  34. $get['customId'] = $this->customId;
  35. $get['className'] = $info['name'] ?? '';
  36. $get['classCover'] = $info['cover'] ?? '';
  37. $get['applyTime'] = date("Y-m-d H:i:s");
  38. $get['status'] = PxApplyClass::STATUS_UN_CONFIRM;
  39. PxApplyClass::addApply($get, $this->shop);
  40. util::complete();
  41. }
  42. //新学员 学员管理 ssh 2021.3.17
  43. public function actionList()
  44. {
  45. $where = ['shopId' => $this->shopId];
  46. $respond = PxApplyClass::getApplyList($where);
  47. util::success($respond);
  48. }
  49. public function actionWxPay()
  50. {
  51. ini_set('date.timezone', 'Asia/Shanghai');
  52. $post = Yii::$app->request->post();
  53. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  54. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  55. $order = PxApplyClass::getByCondition(['customId'=> $this->customId,'orderSn' => $orderSn,'status'=>PxApplyClass::STATUS_UN_CONFIRM]);
  56. if (empty($order)) {
  57. util::fail('订单号无效');
  58. }
  59. //验证优惠券是否还有效
  60. if (!empty($couponId)) {
  61. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  62. }
  63. $name = $orderSn;
  64. $totalFee = $order['actPrice'];
  65. $wxPayType = 0;
  66. //小程序使用miniOpenId
  67. if (httpUtil::isMiniProgram()) {
  68. $openId = $this->user['miniOpenId'];
  69. $wxPayType = 1;
  70. } else {
  71. $openId = $this->user['openId'];
  72. }
  73. $typeList = dict::getConfig('capitalType');
  74. $capitalType = $typeList['pxApply']['id'];
  75. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  76. //订单30分钟后过期
  77. $now = time();
  78. $expireTime = $now + 1800;
  79. $wx = Yii::getAlias("@vendor/weixin");
  80. require_once($wx . '/lib/WxPay.Api.php');
  81. require_once($wx . '/example/WxPay.JsApiPay.php');
  82. $input = new \WxPayUnifiedOrder();
  83. $input->SetBody($name);
  84. $input->SetOut_trade_no($orderSn);
  85. $input->SetTotal_fee($totalFee * 100);
  86. $input->SetTime_start(date("YmdHis", $now));
  87. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  88. $input->SetTime_expire(date("YmdHis", $expireTime));
  89. $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
  90. $input->SetTrade_type("JSAPI");
  91. //花卉宝代为申请的微信支付
  92. $sjExtend = $this->sjExtend;
  93. if ($sjExtend['wxPayApply'] == 1) {
  94. $input->SetSub_openid($openId);
  95. } else {
  96. $input->SetOpenid($openId);
  97. }
  98. //小程序使用miniAppId
  99. if (httpUtil::isMiniProgram()) {
  100. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  101. }
  102. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  103. $tools = new \JsApiPay();
  104. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  105. $newParams = json_decode($jsApiParameters, true);
  106. $current = date("Y-m-d H:i:s");
  107. $updateData = ['deadline' => $current, 'changePrice' => 2];
  108. // PurchaseClass::updateById($id, $updateData);
  109. util::success($newParams);
  110. }
  111. }