RechargeController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace shop\controllers;
  3. use biz\merchant\classes\MerchantClass;
  4. use biz\recharge\classes\RechargeClass;
  5. use biz\wx\classes\WxOpenClass;
  6. use common\components\configDict;
  7. use common\components\httpUtil;
  8. use common\components\util;
  9. use Yii;
  10. class RechargeController extends BaseController
  11. {
  12. //充值记录 shish 2021.2.21
  13. public function actionList()
  14. {
  15. $where = ['shopId' => $this->shopId, 'payStatus' => RechargeClass::PAY_STATUS_HAS_PAY];
  16. $list = RechargeClass::getRechargeList($where);
  17. util::success($list);
  18. }
  19. //免费续期活动 shish 2021.2.21
  20. public function actionRenew()
  21. {
  22. $data = [
  23. 'renew' => 3980,
  24. 'recharge' => 5980,
  25. 'shopName' => '纯彩花艺',
  26. 'userNum' => 150,
  27. 'userAvatar' => [
  28. Yii::$app->params['imgHost'] . '/hhb_small.png',
  29. Yii::$app->params['imgHost'] . '/hhb_small.png',
  30. ],
  31. ];
  32. util::success($data);
  33. }
  34. //续期充值付款 shish 2021.2.21
  35. public function actionRenewPay()
  36. {
  37. ini_set('date.timezone', 'Asia/Shanghai');
  38. $wxPay = configDict::getConfig('payWay', 'weixinPay');
  39. $data = [
  40. 'amount' => 5980,
  41. 'payWay' => $wxPay,
  42. 'sjId' => $this->sjId,
  43. 'sjStyle' => MerchantClass::STYLE_RETAIL,
  44. 'shopId' => $this->shopId,
  45. 'modPrice' => 0,
  46. 'remark' => '免费续期充值',
  47. ];
  48. $order = RechargeClass::addOrder($data);
  49. $orderSn = $order['orderSn'];
  50. $name = $order['orderName'] ?? '充值';
  51. $totalFee = $order['amount'];
  52. //强制使用小程序的miniOpenId
  53. $openId = $this->admin['miniOpenId'];
  54. $capitalTypeData = configDict::getConfig('capitalType');
  55. $capitalType = $capitalTypeData['xhRecharge']['id'];
  56. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  57. $wxPayType = 0;
  58. if (httpUtil::isMiniProgram()) {
  59. $wxPayType = 1;
  60. }
  61. $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  62. //订单30分钟后过期
  63. $now = time();
  64. $expireTime = $now + 1800;
  65. $wx = Yii::getAlias("@vendor/weixin");
  66. require_once($wx . '/lib/WxPay.Api.php');
  67. require_once($wx . '/example/WxPay.JsApiPay.php');
  68. $input = new \WxPayUnifiedOrder();
  69. $input->SetBody($name);
  70. $input->SetOut_trade_no($orderSn);
  71. $input->SetTotal_fee($totalFee * 100);
  72. $input->SetTime_start(date("YmdHis", $now));
  73. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  74. $input->SetTime_expire(date("YmdHis", $expireTime));
  75. $input->SetNotify_url(Yii::$app->params['shopHost'] . '/notice/wx-callback/');
  76. $input->SetTrade_type("JSAPI");
  77. $merchantExtend = WxOpenClass::getWxInfo();
  78. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  79. $input->SetSub_openid($openId);
  80. } else {
  81. $input->SetOpenid($openId);
  82. }
  83. //强制使用小程序的AppId
  84. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  85. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  86. $tools = new \JsApiPay();
  87. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  88. $newParams = json_decode($jsApiParameters, true);
  89. util::success($newParams);
  90. }
  91. //续期成功 shish 2021.2.21
  92. public function actionRenewSuccess()
  93. {
  94. $sj = $this->sj;
  95. $deadline = date("Y-m-d H:i", strtotime($sj['deadline']));
  96. util::success(['deadline' => $deadline]);
  97. }
  98. }