RechargeController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $shopAdmin = $this->shopAdmin;
  28. $shopAdminName = $shopAdmin['name'] ?? '';
  29. $data = [
  30. 'amount' => $amount,
  31. 'payWay' => $wxPay,
  32. 'sjId' => $this->sjId,
  33. 'sjStyle' => SjClass::STYLE_RETAIL,
  34. 'shopId' => $this->shopId,
  35. 'modPrice' => 0,
  36. 'remark' => '',
  37. 'shopAdminId' => $this->shopAdminId,
  38. 'shopAdminName' => $shopAdminName,
  39. ];
  40. $order = RechargeClass::addOrder($data, true);
  41. $orderSn = $order->orderSn;
  42. $name = $order->orderName ?? '充值';
  43. $totalFee = $order->amount;
  44. //强制使用小程序的miniOpenId
  45. $openId = $this->admin['miniOpenId'];
  46. $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
  47. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  48. $wxPayType = httpUtil::isMiniProgram() ? 1 : 0;
  49. $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  50. //订单30分钟后过期
  51. $now = time();
  52. $expireTime = $now + 1800;
  53. $wx = Yii::getAlias("@vendor/weixin");
  54. require_once($wx . '/lib/WxPay.Api.php');
  55. require_once($wx . '/example/WxPay.JsApiPay.php');
  56. $input = new \WxPayUnifiedOrder();
  57. $input->SetBody($name);
  58. $input->SetOut_trade_no($orderSn);
  59. $input->SetTotal_fee($totalFee * 100);
  60. $input->SetTime_start(date("YmdHis", $now));
  61. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  62. $input->SetTime_expire(date("YmdHis", $expireTime));
  63. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  64. $input->SetTrade_type("JSAPI");
  65. $merchantExtend = WxOpenClass::getGhsWxInfo();
  66. $input->SetOpenid($openId);
  67. //强制使用小程序的AppId
  68. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  69. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  70. $tools = new \JsApiPay();
  71. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  72. $newParams = json_decode($jsApiParameters, true);
  73. util::success($newParams);
  74. }
  75. }