PxApplyController.php 3.5 KB

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