RechargeController.php 6.9 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::getDict('payWay', 'wxPay');
  48. $price = getenv('RECHARGE_PRICE') == false ? 5980 : getenv('RECHARGE_PRICE');
  49. $shopAdmin = $this->shopAdmin;
  50. $shopAdminName = $shopAdmin['name'] ?? '';
  51. $data = [
  52. 'amount' => $price,
  53. 'payWay' => $wxPay,
  54. 'sjId' => $this->sjId,
  55. 'sjStyle' => SjClass::STYLE_RETAIL,
  56. 'shopId' => $this->shopId,
  57. 'modPrice' => 0,
  58. 'remark' => '免费续期充值',
  59. 'shopAdminId' => $this->shopAdminId,
  60. 'shopAdminName' => $shopAdminName,
  61. ];
  62. $order = RechargeClass::addOrder($data, true);
  63. $orderSn = $order->orderSn;
  64. $name = $order->orderName ?? '充值';
  65. $totalFee = $order->amount;
  66. //强制使用小程序的miniOpenId
  67. $openId = $this->admin['miniOpenId'];
  68. $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
  69. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  70. $wxPayType = 1;
  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::getDict('payWay', 'wxPay');
  108. $shopAdmin = $this->shopAdmin;
  109. $shopAdminName = $shopAdmin['name'] ?? '';
  110. $data = [
  111. 'amount' => $amount,
  112. 'payWay' => $wxPay,
  113. 'sjId' => $this->sjId,
  114. 'sjStyle' => SjClass::STYLE_RETAIL,
  115. 'shopId' => $this->shopId,
  116. 'modPrice' => 0,
  117. 'remark' => '',
  118. 'shopAdminId' => $this->shopAdminId,
  119. 'shopAdminName' => $shopAdminName,
  120. ];
  121. $order = RechargeClass::addOrder($data, true);
  122. $orderSn = $order->orderSn;
  123. $name = $order->orderName ?? '充值';
  124. $totalFee = $order->amount;
  125. //强制使用小程序的miniOpenId
  126. $openId = $this->admin['miniOpenId'];
  127. $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
  128. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  129. $wxPayType = 1;
  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. }