PxApplyController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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->sjId);
  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 = PxApplyClass::addApply($get, $this->shop);
  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. $post = Yii::$app->request->post();
  51. $orderSn = $post['orderSn'] ?? 0;
  52. $couponId = 0;
  53. $order = PxApplyClass::getByCondition(['customId' => $this->customId, 'orderSn' => $orderSn, 'status' => PxApplyClass::STATUS_UN_CONFIRM]);
  54. if (empty($order)) {
  55. util::fail('订单号无效');
  56. }
  57. $name = $orderSn;
  58. $totalFee = $order['actPrice'];
  59. //强制使用小程序miniOpenId,不再考虑web
  60. $openId = $this->user['miniOpenId'];
  61. $wxPayType = 1;
  62. $typeList = dict::getConfig('capitalType');
  63. $capitalType = $typeList['pxApply']['id'];
  64. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  65. //订单30分钟后过期
  66. $now = time();
  67. $expireTime = $now + 1800;
  68. $wx = Yii::getAlias("@vendor/weixin");
  69. require_once($wx . '/lib/WxPay.Api.php');
  70. require_once($wx . '/example/WxPay.JsApiPay.php');
  71. $input = new \WxPayUnifiedOrder();
  72. $input->SetBody($name);
  73. $input->SetOut_trade_no($orderSn);
  74. $input->SetTotal_fee($totalFee * 100);
  75. $input->SetTime_start(date("YmdHis", $now));
  76. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  77. $input->SetTime_expire(date("YmdHis", $expireTime));
  78. $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
  79. $input->SetTrade_type("JSAPI");
  80. $input->SetOpenid($openId);
  81. $sjExtend = WxOpenClass::getMallWxInfo();
  82. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  83. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  84. $tools = new \JsApiPay();
  85. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  86. $newParams = json_decode($jsApiParameters, true);
  87. util::success($newParams);
  88. }
  89. }