RechargeController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace shop\controllers;
  3. use biz\merchant\classes\MerchantClass;
  4. use biz\recharge\classes\RechargeClass;
  5. use biz\wx\classes\WxOpenClass;
  6. use common\components\configDict;
  7. use common\components\httpUtil;
  8. use common\components\util;
  9. use Yii;
  10. class RechargeController extends BaseController
  11. {
  12. //免费续期活动 shish 2021.2.21
  13. public function actionRenew()
  14. {
  15. $data = [
  16. 'renew' => 3980,
  17. 'recharge' => 5980,
  18. 'shopName' => '纯彩花艺',
  19. 'userNum' => 150,
  20. 'userAvatar' => [
  21. Yii::$app->params['imgHost'] . '/hhb_small.png',
  22. Yii::$app->params['imgHost'] . '/hhb_small.png',
  23. ],
  24. ];
  25. util::success($data);
  26. }
  27. //续期充值付款 shish 2021.2.21
  28. public function actionRenewPay()
  29. {
  30. ini_set('date.timezone', 'Asia/Shanghai');
  31. $wxPay = configDict::getConfig('payWay', 'weixinPay');
  32. $data = [
  33. 'amount' => 5980,
  34. 'payWay' => $wxPay,
  35. 'sjId' => $this->sjId,
  36. 'sjStyle' => MerchantClass::STYLE_RETAIL,
  37. 'shopId' => $this->shopId,
  38. 'modPrice' => 0,
  39. ];
  40. $order = RechargeClass::addOrder($data);
  41. $orderSn = $order['orderSn'];
  42. $name = $order['orderName'] ?? '充值';
  43. $totalFee = $order['amount'];
  44. //强制使用小程序的miniOpenId
  45. $openId = $this->admin['miniOpenId'];
  46. $capitalTypeData = configDict::getConfig('capitalType');
  47. $capitalType = $capitalTypeData['xhRecharge']['id'];
  48. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  49. $wxPayType = 0;
  50. if (httpUtil::isMiniProgram()) {
  51. $wxPayType = 1;
  52. }
  53. $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  54. //订单30分钟后过期
  55. $now = time();
  56. $expireTime = $now + 1800;
  57. $wx = Yii::getAlias("@vendor/weixin");
  58. require_once($wx . '/lib/WxPay.Api.php');
  59. require_once($wx . '/example/WxPay.JsApiPay.php');
  60. $input = new \WxPayUnifiedOrder();
  61. $input->SetBody($name);
  62. $input->SetOut_trade_no($orderSn);
  63. $input->SetTotal_fee($totalFee * 100);
  64. $input->SetTime_start(date("YmdHis", $now));
  65. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  66. $input->SetTime_expire(date("YmdHis", $expireTime));
  67. $input->SetNotify_url(Yii::$app->params['shopHost'] . '/notice/wx-callback/');
  68. $input->SetTrade_type("JSAPI");
  69. $merchantExtend = WxOpenClass::getWxInfo();
  70. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  71. $input->SetSub_openid($openId);
  72. } else {
  73. $input->SetOpenid($openId);
  74. }
  75. //强制使用小程序的AppId
  76. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  77. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  78. $tools = new \JsApiPay();
  79. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  80. $newParams = json_decode($jsApiParameters, true);
  81. util::success($newParams);
  82. }
  83. //续期成功 shish 2021.2.21
  84. public function actionRenewSuccess()
  85. {
  86. $sj = $this->sj;
  87. $deadline = date("Y-m-d H:i", strtotime($sj['deadline']));
  88. util::success(['deadline' => $deadline]);
  89. }
  90. }