RechargeController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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::getDict('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. $capitalType = dict::getDict('capitalType','xhRecharge','id');
  65. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  66. $wxPayType = 0;
  67. if (httpUtil::isMiniProgram()) {
  68. $wxPayType = 1;
  69. }
  70. $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType . '&rechargeRenew=1';
  71. //订单30分钟后过期
  72. $now = time();
  73. $expireTime = $now + 1800;
  74. $wx = Yii::getAlias("@vendor/weixin");
  75. require_once($wx . '/lib/WxPay.Api.php');
  76. require_once($wx . '/example/WxPay.JsApiPay.php');
  77. $input = new \WxPayUnifiedOrder();
  78. $input->SetBody($name);
  79. $input->SetOut_trade_no($orderSn);
  80. $input->SetTotal_fee($totalFee * 100);
  81. $input->SetTime_start(date("YmdHis", $now));
  82. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  83. $input->SetTime_expire(date("YmdHis", $expireTime));
  84. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  85. $input->SetTrade_type("JSAPI");
  86. $merchantExtend = WxOpenClass::getWxInfo();
  87. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  88. $input->SetSub_openid($openId);
  89. } else {
  90. $input->SetOpenid($openId);
  91. }
  92. //强制使用小程序的AppId
  93. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  94. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  95. $tools = new \JsApiPay();
  96. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  97. $newParams = json_decode($jsApiParameters, true);
  98. util::success($newParams);
  99. }
  100. //充值余额 ssh 2021.2.21
  101. public function actionBalance()
  102. {
  103. ini_set('date.timezone', 'Asia/Shanghai');
  104. $get = Yii::$app->request->get();
  105. $amount = $get['amount'] ?? 500;
  106. $wxPay = dict::getDict('payWay', 'wxPay');
  107. $data = [
  108. 'amount' => $amount,
  109. 'payWay' => $wxPay,
  110. 'sjId' => $this->sjId,
  111. 'sjStyle' => SjClass::STYLE_RETAIL,
  112. 'shopId' => $this->shopId,
  113. 'modPrice' => 0,
  114. 'remark' => '',
  115. ];
  116. $order = RechargeClass::addOrder($data);
  117. $orderSn = $order['orderSn'];
  118. $name = $order['orderName'] ?? '充值';
  119. $totalFee = $order['amount'];
  120. //强制使用小程序的miniOpenId
  121. $openId = $this->admin['miniOpenId'];
  122. $capitalType = dict::getDict('capitalType','xhRecharge','id');
  123. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  124. $wxPayType = 0;
  125. if (httpUtil::isMiniProgram()) {
  126. $wxPayType = 1;
  127. }
  128. $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  129. //订单30分钟后过期
  130. $now = time();
  131. $expireTime = $now + 1800;
  132. $wx = Yii::getAlias("@vendor/weixin");
  133. require_once($wx . '/lib/WxPay.Api.php');
  134. require_once($wx . '/example/WxPay.JsApiPay.php');
  135. $input = new \WxPayUnifiedOrder();
  136. $input->SetBody($name);
  137. $input->SetOut_trade_no($orderSn);
  138. $input->SetTotal_fee($totalFee * 100);
  139. $input->SetTime_start(date("YmdHis", $now));
  140. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  141. $input->SetTime_expire(date("YmdHis", $expireTime));
  142. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  143. $input->SetTrade_type("JSAPI");
  144. $merchantExtend = WxOpenClass::getWxInfo();
  145. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  146. $input->SetSub_openid($openId);
  147. } else {
  148. $input->SetOpenid($openId);
  149. }
  150. //强制使用小程序的AppId
  151. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  152. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  153. $tools = new \JsApiPay();
  154. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  155. $newParams = json_decode($jsApiParameters, true);
  156. util::success($newParams);
  157. }
  158. //续期成功 ssh 2021.2.21
  159. public function actionRenewSuccess()
  160. {
  161. $sj = $this->sj;
  162. $deadline = date("Y-m-d H:i", strtotime($sj['deadline']));
  163. util::success(['deadline' => $deadline]);
  164. }
  165. }