RechargeController.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\classes\MerchantClass;
  4. use biz\recharge\classes\RechargeClass;
  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 actionBalance()
  22. {
  23. ini_set('date.timezone', 'Asia/Shanghai');
  24. $get = Yii::$app->request->get();
  25. $amount = $get['amount'] ?? 500;
  26. $wxPay = dict::getDict('payWay', 'wxPay');
  27. $data = [
  28. 'amount' => $amount,
  29. 'payWay' => $wxPay,
  30. 'sjId' => $this->sjId,
  31. 'sjStyle' => SjClass::STYLE_RETAIL,
  32. 'shopId' => $this->shopId,
  33. 'modPrice' => 0,
  34. 'remark' => '',
  35. ];
  36. $order = RechargeClass::addOrder($data, true);
  37. $orderSn = $order->orderSn;
  38. $name = $order->orderName ?? '充值';
  39. $totalFee = $order->amount;
  40. //强制使用小程序的miniOpenId
  41. $openId = $this->admin['miniOpenId'];
  42. $capitalType = dict::getDict('capitalType', '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. $input->SetOpenid($openId);
  63. //强制使用小程序的AppId
  64. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  65. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  66. $tools = new \JsApiPay();
  67. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  68. $newParams = json_decode($jsApiParameters, true);
  69. util::success($newParams);
  70. }
  71. }