RechargeController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\classes\MerchantClass;
  4. use biz\recharge\classes\RechargeClass;
  5. use bizHd\wx\classes\WxOpenClass;
  6. use common\components\dict;
  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 actionBalance()
  21. {
  22. ini_set('date.timezone', 'Asia/Shanghai');
  23. $get = Yii::$app->request->get();
  24. $amount = $get['amount'] ?? 500;
  25. $wxPay = dict::getConfig('payWay', 'wxPay');
  26. $data = [
  27. 'amount' => $amount,
  28. 'payWay' => $wxPay,
  29. 'sjId' => $this->sjId,
  30. 'sjStyle' => MerchantClass::STYLE_RETAIL,
  31. 'shopId' => $this->shopId,
  32. 'modPrice' => 0,
  33. 'remark' => '',
  34. ];
  35. $order = RechargeClass::addOrder($data);
  36. $orderSn = $order['orderSn'];
  37. $name = $order['orderName'] ?? '充值';
  38. $totalFee = $order['amount'];
  39. //强制使用小程序的miniOpenId
  40. $openId = $this->admin['miniOpenId'];
  41. $capitalTypeData = dict::getConfig('capitalType');
  42. $capitalType = $capitalTypeData['xhRecharge']['id'];
  43. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  44. $wxPayType = httpUtil::isMiniProgram() ? 1 : 0;
  45. $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  46. //订单30分钟后过期
  47. $now = time();
  48. $expireTime = $now + 1800;
  49. $wx = Yii::getAlias("@vendor/weixin");
  50. require_once($wx . '/lib/WxPay.Api.php');
  51. require_once($wx . '/example/WxPay.JsApiPay.php');
  52. $input = new \WxPayUnifiedOrder();
  53. $input->SetBody($name);
  54. $input->SetOut_trade_no($orderSn);
  55. $input->SetTotal_fee($totalFee * 100);
  56. $input->SetTime_start(date("YmdHis", $now));
  57. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  58. $input->SetTime_expire(date("YmdHis", $expireTime));
  59. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  60. $input->SetTrade_type("JSAPI");
  61. $merchantExtend = WxOpenClass::getGhsWxInfo();
  62. //平台代为申请支付商户号时使用
  63. //$input->SetSub_openid($openId);
  64. $input->SetOpenid($openId);
  65. //强制使用小程序的AppId
  66. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  67. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  68. $tools = new \JsApiPay();
  69. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  70. $newParams = json_decode($jsApiParameters, true);
  71. util::success($newParams);
  72. }
  73. }