RechargeController.php 6.3 KB

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