RechargeController.php 5.4 KB

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