|
|
@@ -25,6 +25,7 @@ use Yii;
|
|
|
use common\components\util;
|
|
|
use biz\wx\classes\WxMessageClass;
|
|
|
use bizGhs\order\services\OrderService;
|
|
|
+use common\components\lakala\Lakala;
|
|
|
|
|
|
class PurchaseController extends BaseController
|
|
|
{
|
|
|
@@ -696,44 +697,48 @@ class PurchaseController extends BaseController
|
|
|
util::success(['hasError' => 1, 'hasNoMiniOpenId' => 1]);
|
|
|
}
|
|
|
$purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
|
|
|
- //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
|
|
|
- $wxPayType = 0;
|
|
|
- if (httpUtil::isMiniProgram()) {
|
|
|
- $wxPayType = 1;
|
|
|
- }
|
|
|
- $attach = "couponId=" . $couponId . "&capitalType=" . $purchaseCapital . '&wxPayType=' . $wxPayType;
|
|
|
- //订单30分钟后过期
|
|
|
- $now = time();
|
|
|
- $expireTime = $now + 1800;
|
|
|
-
|
|
|
- $wx = Yii::getAlias("@vendor/weixin");
|
|
|
- require_once($wx . '/lib/WxPay.Api.php');
|
|
|
- require_once($wx . '/example/WxPay.JsApiPay.php');
|
|
|
- $input = new \WxPayUnifiedOrder();
|
|
|
- $input->SetBody($name);
|
|
|
- $input->SetOut_trade_no($orderSn);
|
|
|
- $input->SetTotal_fee($totalFee * 100);
|
|
|
- $input->SetTime_start(date("YmdHis", $now));
|
|
|
- //将流水类型、代金劵等传给微信再回传
|
|
|
- $input->SetAttach($attach);
|
|
|
- $input->SetTime_expire(date("YmdHis", $expireTime));
|
|
|
- $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
|
|
|
- $input->SetTrade_type("JSAPI");
|
|
|
+
|
|
|
//花卉宝代为申请的微信支付
|
|
|
$merchantExtend = WxOpenClass::getWxInfo();
|
|
|
|
|
|
- if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
|
|
|
- $input->SetSub_openid($openId);
|
|
|
- } else {
|
|
|
- $input->SetOpenid($openId);
|
|
|
+ $ghsId = $order->ghsId ?? 0;
|
|
|
+ $ghs = GhsClass::getById($ghsId, true);
|
|
|
+ if (empty($ghs)) {
|
|
|
+ util::fail('没有供货商信息');
|
|
|
}
|
|
|
-
|
|
|
- //强制使用小程序的miniAppId
|
|
|
- $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
- $tools = new \JsApiPay();
|
|
|
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
- $newParams = json_decode($jsApiParameters, true);
|
|
|
+ $ghsShopId = $ghs->shopId ?? 0;
|
|
|
+ $ghsShop = ShopClass::getById($ghsShopId, true);
|
|
|
+ if (empty($ghsShop)) {
|
|
|
+ util::fail('没有供货商门店信息');
|
|
|
+ }
|
|
|
+
|
|
|
+ $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
|
|
|
+ $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
|
|
|
+ $params = [
|
|
|
+ 'appid' => 'OP00002119',
|
|
|
+ 'serial_no' => '018b08cfddbd',
|
|
|
+ 'merchant_no' => $ghsShop->lklSjNo,
|
|
|
+ 'term_no' => $ghsShop->lklScanTermNo,
|
|
|
+ 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
|
|
|
+ 'lklCertificatePath' => $lklCertificatePath,
|
|
|
+ ];
|
|
|
+ $laResource = new Lakala($params);
|
|
|
+ $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
|
|
|
+ $wxParams = [
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'amount' => $totalFee,
|
|
|
+ 'capitalType' => $purchaseCapital,
|
|
|
+ 'notifyUrl' => $notifyUrl,
|
|
|
+ 'wxAppId' => $merchantExtend['miniAppId'],
|
|
|
+ 'openId' => $openId,
|
|
|
+ 'subject' => $name,
|
|
|
+ 'couponId' => $couponId,
|
|
|
+ ];
|
|
|
+ $response = $laResource->driveWxPay($wxParams);
|
|
|
+ if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
|
|
|
+ util::fail('下单失败');
|
|
|
+ }
|
|
|
+ $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
|
|
|
$newParams['id'] = $id;
|
|
|
util::success($newParams);
|
|
|
}
|