PxApplyController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 common\components\dict;
  7. use common\components\util;
  8. use Yii;
  9. use bizHd\wx\classes\WxOpenClass;
  10. /**
  11. * 培训报名
  12. */
  13. class PxApplyController extends BaseController
  14. {
  15. //报名申请 ssh 2021.3.17
  16. public function actionAdd()
  17. {
  18. $get = Yii::$app->request->get();
  19. $classId = $get['classId'] ?? 0;
  20. $info = PxClassClass::getClassInfo($classId);
  21. PxClassClass::valid($info, $this->sjId);
  22. $customId = $this->customId;
  23. if (empty($customId)) {
  24. util::fail('没有找到学员信息');
  25. }
  26. $custom = CustomClass::getCustomInfo($customId);
  27. if (empty($custom)) {
  28. util::fail('没有学员信息');
  29. }
  30. CustomClass::valid($custom, $this->shopId);
  31. $get['sjId'] = $this->sjId;
  32. $get['prePrice'] = $info['tuition'];
  33. $get['actPrice'] = $info['tuition'];
  34. $get['shopId'] = $this->shopId;
  35. $get['shopAdminId'] = 0;
  36. $get['customId'] = $this->customId;
  37. $get['customName'] = $custom['name'] ?? '';
  38. $get['customAvatar'] = $custom['avatar'] ?? '';
  39. $get['className'] = $info['name'] ?? '';
  40. $get['classCover'] = $info['cover'] ?? '';
  41. $get['applyTime'] = date("Y-m-d H:i:s");
  42. $get['status'] = PxApplyClass::STATUS_UN_CONFIRM;
  43. $respond = \bizHd\px\classes\PxApplyClass::addApply($get, true);
  44. util::success($respond);
  45. }
  46. //新学员 学员管理 ssh 2021.3.17
  47. public function actionList()
  48. {
  49. $where = ['shopId' => $this->shopId];
  50. $respond = PxApplyClass::getApplyList($where);
  51. util::success($respond);
  52. }
  53. public function actionWxPay()
  54. {
  55. ini_set('date.timezone', 'Asia/Shanghai');
  56. $get = Yii::$app->request->get();
  57. $orderSn = $get['orderSn'] ?? '';
  58. if (empty($orderSn)) {
  59. util::fail('没有订单号');
  60. }
  61. $couponId = 0;
  62. $order = PxApplyClass::getByCondition(['customId' => $this->customId, 'orderSn' => $orderSn, 'status' => PxApplyClass::STATUS_UN_CONFIRM]);
  63. if (empty($order)) {
  64. util::fail('订单号无效');
  65. }
  66. $name = $orderSn;
  67. $totalFee = $order['actPrice'];
  68. //强制使用小程序miniOpenId,不再考虑web
  69. $openId = $this->user['miniOpenId'];
  70. $wxPayType = 1;
  71. $capitalType = dict::getDict('capitalType', 'pxApply', 'id');
  72. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  73. //订单30分钟后过期
  74. $now = time();
  75. $expireTime = $now + 1800;
  76. $wx = Yii::getAlias("@vendor/weixin");
  77. require_once($wx . '/lib/WxPay.Api.php');
  78. require_once($wx . '/example/WxPay.JsApiPay.php');
  79. $input = new \WxPayUnifiedOrder();
  80. $input->SetBody($name);
  81. $input->SetOut_trade_no($orderSn);
  82. $input->SetTotal_fee($totalFee * 100);
  83. $input->SetTime_start(date("YmdHis", $now));
  84. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  85. $input->SetTime_expire(date("YmdHis", $expireTime));
  86. $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
  87. $input->SetTrade_type("JSAPI");
  88. $input->SetOpenid($openId);
  89. $sjExtend = WxOpenClass::getMallWxInfo();
  90. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  91. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  92. $tools = new \JsApiPay();
  93. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  94. $newParams = json_decode($jsApiParameters, true);
  95. util::success($newParams);
  96. }
  97. }