RechargeController.php 6.8 KB

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