RechargeController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace hd\controllers;
  3. use biz\sj\classes\MerchantClass;
  4. use biz\recharge\classes\RechargeClass;
  5. use bizHd\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 actionList()
  14. {
  15. $where = ['shopId' => $this->shopId, 'payStatus' => RechargeClass::PAY_STATUS_HAS_PAY];
  16. $list = RechargeClass::getRechargeList($where);
  17. util::success($list);
  18. }
  19. //免费续期活动 shish 2021.2.21
  20. public function actionRenew()
  21. {
  22. $data = [
  23. 'renew' => 3980,
  24. 'recharge' => 5980,
  25. 'shopName' => '纯彩花艺',
  26. 'userNum' => 150,
  27. 'userAvatar' => [
  28. Yii::$app->params['imgHost'] . '/hhb_small.png',
  29. Yii::$app->params['imgHost'] . '/hhb_small.png',
  30. ],
  31. ];
  32. util::success($data);
  33. }
  34. //续期充值付款 shish 2021.2.21
  35. public function actionRenewPay()
  36. {
  37. ini_set('date.timezone', 'Asia/Shanghai');
  38. $wxPay = configDict::getConfig('payWay', 'weixinPay');
  39. $data = [
  40. 'amount' => 5980,
  41. 'payWay' => $wxPay,
  42. 'sjId' => $this->sjId,
  43. 'sjStyle' => MerchantClass::STYLE_RETAIL,
  44. 'shopId' => $this->shopId,
  45. 'modPrice' => 0,
  46. 'remark' => '免费续期充值',
  47. ];
  48. $order = RechargeClass::addOrder($data);
  49. $orderSn = $order['orderSn'];
  50. $name = $order['orderName'] ?? '充值';
  51. $totalFee = $order['amount'];
  52. //强制使用小程序的miniOpenId
  53. $openId = $this->admin['miniOpenId'];
  54. $capitalTypeData = configDict::getConfig('capitalType');
  55. $capitalType = $capitalTypeData['xhRecharge']['id'];
  56. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  57. $wxPayType = 0;
  58. if (httpUtil::isMiniProgram()) {
  59. $wxPayType = 1;
  60. }
  61. $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  62. //订单30分钟后过期
  63. $now = time();
  64. $expireTime = $now + 1800;
  65. $wx = Yii::getAlias("@vendor/weixin");
  66. require_once($wx . '/lib/WxPay.Api.php');
  67. require_once($wx . '/example/WxPay.JsApiPay.php');
  68. $input = new \WxPayUnifiedOrder();
  69. $input->SetBody($name);
  70. $input->SetOut_trade_no($orderSn);
  71. $input->SetTotal_fee($totalFee * 100);
  72. $input->SetTime_start(date("YmdHis", $now));
  73. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  74. $input->SetTime_expire(date("YmdHis", $expireTime));
  75. $input->SetNotify_url(Yii::$app->params['shopHost'] . '/notice/wx-callback/');
  76. $input->SetTrade_type("JSAPI");
  77. $merchantExtend = WxOpenClass::getWxInfo();
  78. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  79. $input->SetSub_openid($openId);
  80. } else {
  81. $input->SetOpenid($openId);
  82. }
  83. //强制使用小程序的AppId
  84. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  85. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  86. $tools = new \JsApiPay();
  87. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  88. $newParams = json_decode($jsApiParameters, true);
  89. util::success($newParams);
  90. }
  91. //充值余额 shish 2021.2.21
  92. public function actionBalance()
  93. {
  94. ini_set('date.timezone', 'Asia/Shanghai');
  95. $get = Yii::$app->request->get();
  96. $amount = $get['amount'] ?? 500;
  97. $wxPay = configDict::getConfig('payWay', 'weixinPay');
  98. $data = [
  99. 'amount' => $amount,
  100. 'payWay' => $wxPay,
  101. 'sjId' => $this->sjId,
  102. 'sjStyle' => MerchantClass::STYLE_RETAIL,
  103. 'shopId' => $this->shopId,
  104. 'modPrice' => 0,
  105. 'remark' => '',
  106. ];
  107. $order = RechargeClass::addOrder($data);
  108. $orderSn = $order['orderSn'];
  109. $name = $order['orderName'] ?? '充值';
  110. $totalFee = $order['amount'];
  111. //强制使用小程序的miniOpenId
  112. $openId = $this->admin['miniOpenId'];
  113. $capitalTypeData = configDict::getConfig('capitalType');
  114. $capitalType = $capitalTypeData['xhRecharge']['id'];
  115. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  116. $wxPayType = 0;
  117. if (httpUtil::isMiniProgram()) {
  118. $wxPayType = 1;
  119. }
  120. $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  121. //订单30分钟后过期
  122. $now = time();
  123. $expireTime = $now + 1800;
  124. $wx = Yii::getAlias("@vendor/weixin");
  125. require_once($wx . '/lib/WxPay.Api.php');
  126. require_once($wx . '/example/WxPay.JsApiPay.php');
  127. $input = new \WxPayUnifiedOrder();
  128. $input->SetBody($name);
  129. $input->SetOut_trade_no($orderSn);
  130. $input->SetTotal_fee($totalFee * 100);
  131. $input->SetTime_start(date("YmdHis", $now));
  132. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  133. $input->SetTime_expire(date("YmdHis", $expireTime));
  134. $input->SetNotify_url(Yii::$app->params['shopHost'] . '/notice/wx-callback/');
  135. $input->SetTrade_type("JSAPI");
  136. $merchantExtend = WxOpenClass::getWxInfo();
  137. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  138. $input->SetSub_openid($openId);
  139. } else {
  140. $input->SetOpenid($openId);
  141. }
  142. //强制使用小程序的AppId
  143. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  144. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  145. $tools = new \JsApiPay();
  146. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  147. $newParams = json_decode($jsApiParameters, true);
  148. util::success($newParams);
  149. }
  150. //续期成功 shish 2021.2.21
  151. public function actionRenewSuccess()
  152. {
  153. $sj = $this->sj;
  154. $deadline = date("Y-m-d H:i", strtotime($sj['deadline']));
  155. util::success(['deadline' => $deadline]);
  156. }
  157. }