|
|
@@ -24,415 +24,415 @@ use common\components\util;
|
|
|
|
|
|
class OrderController extends BaseController
|
|
|
{
|
|
|
-
|
|
|
- //商城下单操作 shish 2019.12.3
|
|
|
- public function actionCreateOrder()
|
|
|
- {
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
|
|
|
- $goodsStyleId = isset($post['goodsStyleId']) ? $post['goodsStyleId'] : 0;
|
|
|
- $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
|
|
|
- if (empty($goodsId)) {
|
|
|
- util::fail('请选择商品');
|
|
|
- }
|
|
|
- $goodsInfo = GoodsService::getGoodsInfo($goodsId);
|
|
|
- if (empty($goodsInfo)) {
|
|
|
- util::fail('没有找到商品');
|
|
|
- }
|
|
|
- //确认是否要配送的商品
|
|
|
- $needSend = isset($goodsInfo['needSend']) && $goodsInfo['needSend'] == 1 ? 1 : 0;
|
|
|
-
|
|
|
- $post['userId'] = $this->userId;
|
|
|
- $post['payWay'] = $this->isWx == true ? 0 : 1;
|
|
|
- $defaultShopId = MerchantService::getDefaultShopId($this->merchant);
|
|
|
- if (empty($defaultShopId)) {
|
|
|
- util::fail('没有找到门店');
|
|
|
- }
|
|
|
- $shopInfo = ShopService::getById($defaultShopId);
|
|
|
-
|
|
|
- //计算运费
|
|
|
- $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
|
|
|
- $sendCost = 0;
|
|
|
- if ($needSend == 1) {
|
|
|
- $lat = $post['receiveLat'];//收货人纬度
|
|
|
- $lng = $post['receiveLong'];//收货人经度
|
|
|
- $jsStatDistance = $post['sendDistance'];
|
|
|
- $sendCost = ShopService::getSendCost($lat, $lng, $jsStatDistance, $shopInfo);
|
|
|
- }
|
|
|
- $post['sendCost'] = $sendCost;
|
|
|
- $post['merchantId'] = $this->merchantId;
|
|
|
- $post['shopId'] = $defaultShopId;
|
|
|
-
|
|
|
- //计算总金额
|
|
|
- $unitPrice = $goodsInfo['price'];
|
|
|
- $goodsStyleList = isset($goodsInfo['goodsStyleList']) ? $goodsInfo['goodsStyleList'] : [];
|
|
|
- if (!empty($goodsStyleId)) {
|
|
|
- if (empty($goodsStyleList)) {
|
|
|
- util::fail('商品款式没有找到');
|
|
|
- }
|
|
|
- $styleIdList = array_keys($goodsStyleList);
|
|
|
- if (in_array($goodsId, $styleIdList) == false) {
|
|
|
- util::fail('商品款式没有找到!');
|
|
|
- }
|
|
|
- $unitPrice = $goodsStyleList['price'];
|
|
|
- }
|
|
|
- $goodsPrice = $unitPrice * $goodsNum;
|
|
|
- $prePrice = stringUtil::calcAdd($sendCost, $goodsPrice);
|
|
|
- $actPrice = $prePrice;
|
|
|
- $showPrice = $prePrice;
|
|
|
-
|
|
|
- //计算优惠金额
|
|
|
- $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
|
|
|
- //没有使用优惠券,默认使用会员优惠
|
|
|
- if (empty($couponId)) {
|
|
|
- $discountInfo = UserAssetService::getDiscount($this->userId);
|
|
|
- if (isset($discountInfo['member'])) {
|
|
|
- $discount = $discountInfo['member']['discount'];
|
|
|
- $actPrice = ($actPrice * ($discount * 10000)) / 10000;
|
|
|
- $showPrice = $actPrice;
|
|
|
- }
|
|
|
- } else {
|
|
|
- //验证优惠券有效性
|
|
|
- $discountAmount = CouponService::valid($couponId, $actPrice, $this->userId);
|
|
|
- //优惠券在支付成功后变更状态
|
|
|
- $showPrice = stringUtil::calcSub($actPrice, $discountAmount);
|
|
|
- }
|
|
|
-
|
|
|
- $now = time();
|
|
|
- $expireTime = $now + 1800;//订单30分钟后过期
|
|
|
- $post['deadline'] = $expireTime;
|
|
|
-
|
|
|
- $post['prePrice'] = $prePrice;
|
|
|
- $post['actPrice'] = $actPrice;
|
|
|
- $order = OrderService::addOrder($post);
|
|
|
- $orderId = $order['id'];
|
|
|
- $orderSn = $order['orderSn'];
|
|
|
- $data = [
|
|
|
- 'orderId' => $orderId,
|
|
|
- 'goodsId' => $goodsId,
|
|
|
- 'userId' => $this->userId,
|
|
|
- 'merchantId' => $this->merchantId,
|
|
|
- 'title' => $goodsInfo['goodsName'],
|
|
|
- 'cover' => isset($goodsInfo['shortImgList']) && !empty($goodsInfo['shortImgList']) ? current($goodsInfo['shortImgList']) : '',
|
|
|
- 'unitPrice' => $unitPrice,
|
|
|
- 'num' => $goodsNum,
|
|
|
- 'goodsStyleName' => isset($goodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $goodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
|
|
|
- 'goodsStyleId' => $goodsStyleId,
|
|
|
- 'createTime' => date("Y-m-d H:i:s"),
|
|
|
- ];
|
|
|
- OrderGoodsService::add($data);//创建订单商品列表
|
|
|
- util::success(['orderSn' => $orderSn, 'totalPrice' => $showPrice, 'couponId' => $couponId]);
|
|
|
- }
|
|
|
-
|
|
|
- //下单要用到的相关信息 shish 2019.12.6
|
|
|
- public function actionOrderRelate()
|
|
|
- {
|
|
|
- $regionTree = RegionService::tree();
|
|
|
- $shop = ShopService::getDefaultShop($this->merchant);
|
|
|
- $freight = MerchantExtendService::getFreight($this->merchantExtend);
|
|
|
- $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
|
|
|
- $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey];
|
|
|
- util::success($out);
|
|
|
- }
|
|
|
-
|
|
|
- //余额支付 shish 2019.12.6
|
|
|
- public function actionBalancePay()
|
|
|
- {
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
|
|
|
- $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
|
|
|
- $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
|
|
|
- $order = OrderService::getByOrderSn($orderSn);
|
|
|
-
|
|
|
- //dd(password_hash('123456', PASSWORD_BCRYPT));
|
|
|
-
|
|
|
- //验证支付密码是否正确
|
|
|
- UserService::validPayPassword($payPassword, $this->user);
|
|
|
-
|
|
|
- //验证订单有效性
|
|
|
- OrderService::check($order, $this->userId);
|
|
|
-
|
|
|
- $typeList = configDict::getConfig('capitalType');
|
|
|
- $capitalType = $typeList['xhOrder']['id'];
|
|
|
- $totalFee = $order['actPrice'];
|
|
|
- xhPayToolService::balancePay($orderSn, $totalFee, $capitalType, $couponId);
|
|
|
- util::success(['discountAmount' => 9.9, 'discountType' => 0]);
|
|
|
- }
|
|
|
-
|
|
|
- //获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
|
|
|
- public function actionWxPay()
|
|
|
- {
|
|
|
- ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
|
|
|
- $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
|
|
|
- $order = OrderService::getByOrderSn($orderSn);
|
|
|
- $orderId = $order['id'];
|
|
|
-
|
|
|
- //验证订单有效性
|
|
|
- OrderService::check($order, $this->userId);
|
|
|
-
|
|
|
- $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
|
|
|
- $totalFee = $order['actPrice'];
|
|
|
-
|
|
|
- //小程序使用miniOpenId
|
|
|
- if (httpUtil::isMiniProgram()) {
|
|
|
- $openId = $this->user['miniOpenId'];
|
|
|
- } else {
|
|
|
- $openId = $this->user['openId'];
|
|
|
- }
|
|
|
-
|
|
|
- $typeList = configDict::getConfig('capitalType');
|
|
|
- $capitalType = $typeList['xhOrder']['id'];
|
|
|
- //将流水类型、代金劵传过去
|
|
|
- $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType;
|
|
|
-
|
|
|
- //订单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($this->frontUrl . '/notice/weixin-callback/');
|
|
|
- $input->SetTrade_type("JSAPI");
|
|
|
-
|
|
|
- //花卉宝代为申请的微信支付
|
|
|
- $merchantExtend = $this->merchantExtend;
|
|
|
- if ($merchantExtend['generalMerchant'] == 1) {
|
|
|
- $input->SetSub_openid($openId);
|
|
|
- } else {
|
|
|
- $input->SetOpenid($openId);
|
|
|
- }
|
|
|
- //小程序使用miniAppId
|
|
|
- if (httpUtil::isMiniProgram()) {
|
|
|
- $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
- }
|
|
|
-
|
|
|
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
- $tools = new \JsApiPay();
|
|
|
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
- $newParams = json_decode($jsApiParameters, true);
|
|
|
- //已请求微信不能修改价格
|
|
|
- $updateData = [];
|
|
|
- $updateData['modPrice'] = 0;
|
|
|
- if (empty($order['deadline'])) {
|
|
|
- $updateData['deadline'] = $expireTime;
|
|
|
- }
|
|
|
- OrderService::updateById($orderId, $updateData);
|
|
|
- util::success($newParams);
|
|
|
- }
|
|
|
-
|
|
|
- //快捷付款订单
|
|
|
- public function actionFastPay()
|
|
|
- {
|
|
|
- ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
|
|
|
- $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->merchant);
|
|
|
- //验证门店是否有效
|
|
|
- $shopInfo = ShopService::getById($shopId);
|
|
|
- ShopService::valid($shopInfo, $this->merchantId);
|
|
|
- //门店订单
|
|
|
- $sourceType = 1;
|
|
|
- $post['userId'] = $this->userId;
|
|
|
- $prePrice = round($post['prePrice'], 2);
|
|
|
- $actPrice = $prePrice;
|
|
|
- $post['actPrice'] = $actPrice;
|
|
|
- $post['payStyle'] = 0;
|
|
|
- $post['merchantId'] = $this->merchantId;
|
|
|
- $now = time();
|
|
|
- $expireTime = $now + 300;//订单5分钟后过期
|
|
|
- $post['createTime'] = date("Y-m-d H:i:s", $now);
|
|
|
- $post['deadline'] = $expireTime;
|
|
|
- if ($actPrice <= 0) {
|
|
|
- util::fail('请填写正确的金额');
|
|
|
- }
|
|
|
- //微信支付订单提交不能修改价格
|
|
|
- $post['modPrice'] = $this->isWx ? 0 : 1;
|
|
|
- $post['sourceType'] = $sourceType;
|
|
|
- $order = OrderService::addOrder($post);
|
|
|
- $orderId = $order['id'];
|
|
|
- $orderSn = $order['orderSn'];
|
|
|
- $merchantId = $this->merchantId;
|
|
|
- $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
|
|
|
-
|
|
|
- if ($payWay == 0) {
|
|
|
- $orderId = $order['id'];
|
|
|
- $name = '购买商品';
|
|
|
- $totalFee = $actPrice;
|
|
|
- $user = UserService::getById($this->userId);
|
|
|
- $openId = isset($user['openId']) ? $user['openId'] : 0;
|
|
|
- if (httpUtil::isMiniProgram()) {
|
|
|
- //小程序使用miniOpenId
|
|
|
- $openId = $user['miniOpenId'];
|
|
|
- }
|
|
|
- if (empty($openId)) {
|
|
|
- util::fail('没有找到客户的openId');
|
|
|
- }
|
|
|
- $typeList = configDict::getConfig('capitalType');
|
|
|
- $capitalType = $typeList['xhOrder']['id'];
|
|
|
- $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
|
|
|
- $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));//设置订单有效期5分钟
|
|
|
- $input->SetNotify_url(Yii::$app->params['mHost'] . '/notice/wx-callback/');
|
|
|
- $input->SetTrade_type("JSAPI");
|
|
|
-
|
|
|
- //花卉宝代为申请的微信支付
|
|
|
- $merchantExtend = $this->merchantExtend;
|
|
|
- if ($merchantExtend['generalMerchant'] == 1) {
|
|
|
- $input->SetSub_openid($openId);
|
|
|
- } else {
|
|
|
- $input->SetOpenid($openId);
|
|
|
- }
|
|
|
- //小程序使用miniAppId
|
|
|
- if (httpUtil::isMiniProgram()) {
|
|
|
- $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
- }
|
|
|
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
- $tools = new \JsApiPay();
|
|
|
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
- $newParams = json_decode($jsApiParameters, true);
|
|
|
- $newParams['orderId'] = $orderId;
|
|
|
- util::success($newParams);
|
|
|
-
|
|
|
- } elseif ($payWay == 1) {
|
|
|
- if ($merchantId == 12358) {
|
|
|
- $config = array(
|
|
|
- //应用ID,您的APPID。
|
|
|
- 'app_id' => "2019041663930158",
|
|
|
- //商户私钥,您的原始格式RSA私钥
|
|
|
- 'merchant_private_key' => "MIIEpAIBAAKCAQEA0NGNBMu5BkHU+ztmGhGdsJC1n2ZbXn4uoaYNni2eriPHJHG8vCWL1vv3W+gxX3twnmdQ57s3hFWfd5PIwMm+8QIwiPucckbmTEm2rC2g4j+UnUiXzICJWjlzlCWiBftrsctKKwjsZTPiuDJzUKmYRD4DYWy1+4Uh6k6x98qbALuiFFrh7esvsaSepZfQ+zBLzMVfrtPABkwEtOAzUL4hz4YW+EFfqyj3mu4LP4M+zBWSKRs0iCzJILG/7JA4OEkDJ89gGZ6LiaITUgffV2tg/IS81aNBfutb3tICBr1PLlKYCV0ois54kqmmP7anNrn/KRFI/k6iLd82e1HEoHhvDwIDAQABAoIBAQCr+PgPTAv8CDl0Ek4bCAj7AaJiPTTgVEDpJc0vSNjXB2YZMIZD2RQaoHXtvgLzZMCx49pwjfHBzZZAL3h0tXHIIIqCNd15C8TcbRTBJe7KhZxKEB/b7ruvj4MNLhUKoi3mRcq2OGofSqTcF8h6VMGu6fd0w8f39YOh6N+Od9BBv8aL7CtBwQQihzatBdr2CyjH50TmlVWfEz2YKoZBGRuMy7EzLZgmR5IzEJC36tOBAg5DORNkEMAuzvnmBQznZCtzMZHW5Ytlh/3kbCUMsrWL6ioox/mel4DoQNnQ1kZ60f7Gny3I+0HiJ+vxVBZ3Nyd8FCVbAlq6avkB3ZGoCx0xAoGBAP/Mhf8X81mLK80TQsSWYPmnjnYkOZ7vIpNc/b6/N+BKAAjWB+0wXJ73nhuzB8cuJBz6TK8RE2uUuiUbiVP1jkrQ2EoCWadndKE1fcLFSSOYlN9rxfINcLicdNAFYu0m8He5cqPpW+06sD8HGOlWeBOyPvitXBjBeOB9dPWBpVkpAoGBAND7kruod1T4ErtOavYv4ErlyN0O6PpQR3MBlnzXnJfKLdaMvc/JaqjZtk14Nl9RnBDzN6d93LHxariyuTHw9mdGAPOpxcUEsUdOw56eRIzhyY8lz0c+lvE32r2NypuzK/2BGP5xR+spe7D4esuhLQhUYjByTWbgLQD+7724QrV3AoGAYuO2ib/AnEVpUYa4sTdRljJoqNOoUwEv5Lh2gF98QoFZMhFMTy37IJmpzhuQTjhQTcOWEbgQQe7lZ6MVnBe6QsIqW7I85rLgK9J6I+oRNGmwZA9OHx2DDlut7R2n+Pas0BwpbaSxnSyrJjKgNtTu5u5p2clraUaibGcT6DWOrsECgYEAspjM5aMrmGoJWBnEP3Da9ic6afD8Gi/RX+/TdA2vvekDE4BkFtfDV1n3+mzpyrwr7DBvN6zQlyICWqYirxOHAOtKlPJaGe3Qs2gUtdH8M4oifzuI0RIkXTGmtqgepsGQrq1NduXI2KgzFSLFjpDHs36qC00j6O9chqVYrYJzQDECgYBQyIWx3BBEUgWCbLTT8QeUdf+EnZSLZzIIQFn88zImhqkTSMbpBmcZpI4oOlWiM8i4XOaEzu+EDFIRAchIbVlDgBV1OprAN5BAez03oyh1JkCDYrsEj7FMqWSmbxiY2uubPshMLEGdPU+I46oJTO6FzMyG6hnQrK+/ne0zH8A5LA==",
|
|
|
- //异步通知地址
|
|
|
- 'notify_url' => Yii::$app->params['frontUrl'] . "/notice/alipay-async",
|
|
|
- //同步跳转
|
|
|
- 'return_url' => "",
|
|
|
- //编码格式
|
|
|
- 'charset' => "UTF-8",
|
|
|
- //签名方式
|
|
|
- 'sign_type' => "RSA2",
|
|
|
- //支付宝网关
|
|
|
- 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
|
|
|
- //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
|
|
|
- 'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkFYqNkoWJIx37fGcUBbnZJ+APf14YHO1cBdp9RFSasxj9gm+pwbtK3J6uRuPygK0K/OCgvtuFJ6mZT3tNUEgSZMjnre5Z7IzQnzIBUYFPUEO85s+/RDr5HnAqgOIbu9GL8GWrU6g6uj+QmW591vXckmsbujPx0S3IP+TMOQZWA0JVvDu+T9yGfv3pacKUgdNvYnas/si3278TL4DeIVjZ4OmbbEPmEhD/OhSVlTSWEOdqLuV4DvEpmrGa8XoyfFEtgV9qSVb454Qwu5Nw/ATc9+ssMbN6ROXzOQbAAfqAe6riNUtKEHGVaCynfUAYNyR6yvJb8+VkMR02nBEDC9QHQIDAQAB",
|
|
|
- );
|
|
|
- } else {
|
|
|
- $config = array(
|
|
|
- //应用ID,您的APPID。
|
|
|
- 'app_id' => "2017041906821571",
|
|
|
- //商户私钥,您的原始格式RSA私钥
|
|
|
- 'merchant_private_key' => "MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8dOBKWRRKsHBnlUbPrXV4FcFDeLm0fPfd+iZ/2AaZ1+ix962f3BpYIiq7+f9zaMRazfnw9L8x31pByyMktLs12EkoQ0dHsMxxUzzKAOiiPnvCn8Pv+Jb2qej8GXgCjefutCVNMWGsdwJtMVXEbpdmMa48Wvw+0In5ZS/UG39YAreFzgDqI9jWHE1ZhkGmB1+8hKpeIlEeVGAeYVveUgssMORdA/YY8SWHk26KSIFXBrmdKjAcRJ8Q7ZHUmzIqAV+IMV+RD4J5mZHeJgdAECgYEA8J+Hp1M6eYbT4CPLXa//yRP6Xo+qSzrKHaRB1LRAjYhvKpx/TQetYpNCJ5bWpa+Jp0T5R21pzuYaJkPuGlNEHA13b5T3r1l2ltomSEdaShvD5EZ9WtErYV5zpSv7FjjIGkbwa0H3A8Ydnvw5z4A9TZjjHLjC2GtVGJReqHGglMECgYEAydddA4NRPxmXvIjjmLb1Ft1qwHuyv3vvWhi50foGZXNEnBcfP/OkfyBDDpOEu34GZBMXK9ykHBs1l93OEFGXh7AwW0Lp5lARahBEfBZgPjq5yPO8TOJZrb5hVcuvoDdGjxpRh93XDnQDhWS/1IvUcBLcIsTcnVvfrkX4NLxF/W0CgYEAxamG+gD4rBQBwMImsRN+/2MV7M//iEUG+0qPeXeI/7rv9wUP3etMlwl48qSKNxj37xxN2ksa/Acxu/VZhu6XqKO3VUX+IWFQdaNGh2F13iLozIDLQOtKw3WfcjOq0xpZ5pwXq0RI8iSw+IUhyD8EHNZW2qU8CiRBhyt6hsywqQECgYBa8+06FAachI/XqWfF/UvcDdJ5AkS9/L8SvmmdsSkItjSIkfLHAqdxkbwl6Vu6kUOX/PJIFZjuAWTZFl4xBFNgFYj01uZHnnT6cnIp6HteD2CAqTSFAMqgfFWoL6zoaYAmJBnxO4oZPTYI+ilnQcts5VLFaChx0GCvS2BZgy2W0QKBgQDjP2VtRq4aVSLUq2z1KIDI7GJBbOM5KSW1OEj4sfEdViozPh3Ar/FQWiij1oCZF+iJdKkonHoDbDd+Q0ykcpQ+5Gv07iiT8wJYFR/0j8g2kfql7bVQhGSBeBMS5sawKR3CvkfW73WX+CNnf0PklTY0kTyt6WRXDnKSeyxFVwSZ7g==",
|
|
|
- //异步通知地址
|
|
|
- 'notify_url' => Yii::$app->params['frontUrl'] . "/notice/alipay-async",
|
|
|
- //同步跳转
|
|
|
- 'return_url' => "",
|
|
|
- //编码格式
|
|
|
- 'charset' => "UTF-8",
|
|
|
- //签名方式
|
|
|
- 'sign_type' => "RSA2",
|
|
|
- //支付宝网关
|
|
|
- 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
|
|
|
- //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
|
|
|
- 'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsz3m9juAR1xew4DY6c34gvbwNg8pZ92f932tseKs+4+pF0e+jTDiUo/xHImNDi1KXt1B+s3LxY9L/sxEksbavwmhgbz/igN1cAEwS2YM+Gnf0csDrxAPJhoKL5FTwxPEQ/8VSgroU+6GlF3LAx4VHa1qfn5MqRPfLroJcyPDyGfNe9vna2FnO4E/PH+hVbvPUAwX3XrUvJIm4OgY0JE3HYFlu+O7F4Ln6+Sl+Zv/ZE2nZAvNiyAwW5iVKhKXLieExqwd0NdrP28baBqkkIY+tmV7butGjB52iK1UbU0+1uiaPL4xBxRy6d0LZmYlvdVHp0JRUuwxBLChGgOCo/76DQIDAQAB",
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- $alipayWap = Yii::getAlias("@vendor/alipayWap");
|
|
|
- require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
|
|
|
- require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
|
|
|
-
|
|
|
- $totalFee = $order['actPrice'];
|
|
|
- $out_trade_no = $orderId;//商户订单号,商户网站订单系统中唯一订单号,必填
|
|
|
- $subject = '购买商品';//订单名称,必填
|
|
|
- $total_amount = $totalFee;//付款金额,必填
|
|
|
- $body = '';//商品描述,可空
|
|
|
- $timeout_express = "1m";//超时时间
|
|
|
-
|
|
|
- $typeList = configDict::getConfig('capitalType');
|
|
|
- $capitalType = $typeList['xhOrder']['id'];
|
|
|
- $passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
|
|
|
- $passbackParams = urlencode($passbackParams);
|
|
|
-
|
|
|
- $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
|
|
|
- $payRequestBuilder->setBody($body);
|
|
|
- $payRequestBuilder->setSubject($subject);
|
|
|
- $payRequestBuilder->setOutTradeNo($out_trade_no);
|
|
|
- $payRequestBuilder->setTotalAmount($total_amount);
|
|
|
- $payRequestBuilder->setTimeExpress($timeout_express);
|
|
|
- //在异步通知时将该参数原样返回
|
|
|
- $payRequestBuilder->setPassbackParams($passbackParams);
|
|
|
- //同步通知
|
|
|
- $returnUrl = Yii::$app->params['frontUrl'] . "/notice/pay-alipay-sync";
|
|
|
- //异步通知
|
|
|
- $notifyUrl = Yii::$app->params['frontUrl'] . "/notice/alipay-async";
|
|
|
- $payResponse = new \AlipayTradeService($config);
|
|
|
- $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
|
|
|
- util::success($result);
|
|
|
-
|
|
|
- } elseif ($payWay == 2) {
|
|
|
- //验证支付密码是否正确
|
|
|
- $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
|
|
|
- UserService::validPayPassword($payPassword, $this->user);
|
|
|
- $typeList = configDict::getConfig('capitalType');
|
|
|
- $capitalType = $typeList['xhOrder']['id'];
|
|
|
- $totalFee = $order['actPrice'];
|
|
|
- xhPayToolService::balancePay($orderSn, $totalFee, $capitalType, $couponId);
|
|
|
- util::success(['discountAmount' => 9.9, 'discountType' => 0]);
|
|
|
- } else {
|
|
|
- util::fail('无效的支付方式');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //订单列表 shish 2019.12.12
|
|
|
- public function actionList()
|
|
|
- {
|
|
|
- $where = ['userId' => $this->userId];
|
|
|
- $list = OrderService::getOrderList($where);
|
|
|
- util::success($list);
|
|
|
- }
|
|
|
-
|
|
|
- //订单评价
|
|
|
- public function actionComment()
|
|
|
- {
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $id = $post['id'];
|
|
|
- $order = OrderService::getById($id);
|
|
|
- if ($this->userId != $order['userId']) {
|
|
|
- util::fail('您没有权限操作');
|
|
|
- }
|
|
|
- OrderService::comment($post);
|
|
|
- util::ok('提交成功');
|
|
|
- }
|
|
|
-
|
|
|
- //订单详情 shish 2019.12.16
|
|
|
- public function actionDetail()
|
|
|
- {
|
|
|
- $id = Yii::$app->request->get('id', 0);
|
|
|
- $orderSn = Yii::$app->request->get('orderSn', '');
|
|
|
- $detail = [];
|
|
|
- if (!empty($id)) {
|
|
|
- $detail = OrderService::getOrderById($id);
|
|
|
- }
|
|
|
- if (!empty($orderSn)) {
|
|
|
- $detail = OrderService::getOrderBySn($orderSn);
|
|
|
- }
|
|
|
- OrderService::valid($detail, $this->merchantId);
|
|
|
- util::success($detail);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ //商城下单操作 shish 2019.12.3
|
|
|
+ public function actionCreateOrder()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
|
|
|
+ $goodsStyleId = isset($post['goodsStyleId']) ? $post['goodsStyleId'] : 0;
|
|
|
+ $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
|
|
|
+ if (empty($goodsId)) {
|
|
|
+ util::fail('请选择商品');
|
|
|
+ }
|
|
|
+ $goodsInfo = GoodsService::getGoodsInfo($goodsId);
|
|
|
+ if (empty($goodsInfo)) {
|
|
|
+ util::fail('没有找到商品');
|
|
|
+ }
|
|
|
+ //确认是否要配送的商品
|
|
|
+ $needSend = isset($goodsInfo['needSend']) && $goodsInfo['needSend'] == 1 ? 1 : 0;
|
|
|
+
|
|
|
+ $post['userId'] = $this->userId;
|
|
|
+ $post['payWay'] = $this->isWx == true ? 0 : 1;
|
|
|
+ $defaultShopId = MerchantService::getDefaultShopId($this->merchant);
|
|
|
+ if (empty($defaultShopId)) {
|
|
|
+ util::fail('没有找到门店');
|
|
|
+ }
|
|
|
+ $shopInfo = ShopService::getById($defaultShopId);
|
|
|
+
|
|
|
+ //计算运费
|
|
|
+ $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
|
|
|
+ $sendCost = 0;
|
|
|
+ if ($needSend == 1) {
|
|
|
+ $lat = $post['receiveLat'];//收货人纬度
|
|
|
+ $lng = $post['receiveLong'];//收货人经度
|
|
|
+ $jsStatDistance = $post['sendDistance'];
|
|
|
+ $sendCost = ShopService::getSendCost($lat, $lng, $jsStatDistance, $shopInfo);
|
|
|
+ }
|
|
|
+ $post['sendCost'] = $sendCost;
|
|
|
+ $post['merchantId'] = $this->merchantId;
|
|
|
+ $post['shopId'] = $defaultShopId;
|
|
|
+
|
|
|
+ //计算总金额
|
|
|
+ $unitPrice = $goodsInfo['price'];
|
|
|
+ $goodsStyleList = isset($goodsInfo['goodsStyleList']) ? $goodsInfo['goodsStyleList'] : [];
|
|
|
+ if (!empty($goodsStyleId)) {
|
|
|
+ if (empty($goodsStyleList)) {
|
|
|
+ util::fail('商品款式没有找到');
|
|
|
+ }
|
|
|
+ $styleIdList = array_keys($goodsStyleList);
|
|
|
+ if (in_array($goodsId, $styleIdList) == false) {
|
|
|
+ util::fail('商品款式没有找到!');
|
|
|
+ }
|
|
|
+ $unitPrice = $goodsStyleList['price'];
|
|
|
+ }
|
|
|
+ $goodsPrice = $unitPrice * $goodsNum;
|
|
|
+ $prePrice = stringUtil::calcAdd($sendCost, $goodsPrice);
|
|
|
+ $actPrice = $prePrice;
|
|
|
+ $showPrice = $prePrice;
|
|
|
+
|
|
|
+ //计算优惠金额
|
|
|
+ $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
|
|
|
+ //没有使用优惠券,默认使用会员优惠
|
|
|
+ if (empty($couponId)) {
|
|
|
+ $discountInfo = UserAssetService::getDiscount($this->userId);
|
|
|
+ if (isset($discountInfo['member'])) {
|
|
|
+ $discount = $discountInfo['member']['discount'];
|
|
|
+ $actPrice = ($actPrice * ($discount * 10000)) / 10000;
|
|
|
+ $showPrice = $actPrice;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //验证优惠券有效性
|
|
|
+ $discountAmount = CouponService::valid($couponId, $actPrice, $this->userId);
|
|
|
+ //优惠券在支付成功后变更状态
|
|
|
+ $showPrice = stringUtil::calcSub($actPrice, $discountAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ $now = time();
|
|
|
+ $expireTime = $now + 1800;//订单30分钟后过期
|
|
|
+ $post['deadline'] = $expireTime;
|
|
|
+
|
|
|
+ $post['prePrice'] = $prePrice;
|
|
|
+ $post['actPrice'] = $actPrice;
|
|
|
+ $order = OrderService::addOrder($post);
|
|
|
+ $orderId = $order['id'];
|
|
|
+ $orderSn = $order['orderSn'];
|
|
|
+ $data = [
|
|
|
+ 'orderId' => $orderId,
|
|
|
+ 'goodsId' => $goodsId,
|
|
|
+ 'userId' => $this->userId,
|
|
|
+ 'merchantId' => $this->merchantId,
|
|
|
+ 'title' => $goodsInfo['goodsName'],
|
|
|
+ 'cover' => isset($goodsInfo['shortImgList']) && !empty($goodsInfo['shortImgList']) ? current($goodsInfo['shortImgList']) : '',
|
|
|
+ 'unitPrice' => $unitPrice,
|
|
|
+ 'num' => $goodsNum,
|
|
|
+ 'goodsStyleName' => isset($goodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $goodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
|
|
|
+ 'goodsStyleId' => $goodsStyleId,
|
|
|
+ 'createTime' => date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ OrderGoodsService::add($data);//创建订单商品列表
|
|
|
+ util::success(['orderSn' => $orderSn, 'totalPrice' => $showPrice, 'couponId' => $couponId]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //下单要用到的相关信息 shish 2019.12.6
|
|
|
+ public function actionOrderRelate()
|
|
|
+ {
|
|
|
+ $regionTree = RegionService::tree();
|
|
|
+ $shop = ShopService::getDefaultShop($this->merchant);
|
|
|
+ $freight = MerchantExtendService::getFreight($this->merchantExtend);
|
|
|
+ $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
|
|
|
+ $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey];
|
|
|
+ util::success($out);
|
|
|
+ }
|
|
|
+
|
|
|
+ //余额支付 shish 2019.12.6
|
|
|
+ public function actionBalancePay()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
|
|
|
+ $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
|
|
|
+ $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
|
|
|
+ $order = OrderService::getByOrderSn($orderSn);
|
|
|
+
|
|
|
+ //dd(password_hash('123456', PASSWORD_BCRYPT));
|
|
|
+
|
|
|
+ //验证支付密码是否正确
|
|
|
+ UserService::validPayPassword($payPassword, $this->user);
|
|
|
+
|
|
|
+ //验证订单有效性
|
|
|
+ OrderService::check($order, $this->userId);
|
|
|
+
|
|
|
+ $typeList = configDict::getConfig('capitalType');
|
|
|
+ $capitalType = $typeList['xhOrder']['id'];
|
|
|
+ $totalFee = $order['actPrice'];
|
|
|
+ xhPayToolService::balancePay($orderSn, $totalFee, $capitalType, $couponId);
|
|
|
+ util::success(['discountAmount' => 9.9, 'discountType' => 0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
|
|
|
+ public function actionWxPay()
|
|
|
+ {
|
|
|
+ ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
|
|
|
+ $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
|
|
|
+ $order = OrderService::getByOrderSn($orderSn);
|
|
|
+ $orderId = $order['id'];
|
|
|
+
|
|
|
+ //验证订单有效性
|
|
|
+ OrderService::check($order, $this->userId);
|
|
|
+
|
|
|
+ $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
|
|
|
+ $totalFee = $order['actPrice'];
|
|
|
+
|
|
|
+ //小程序使用miniOpenId
|
|
|
+ if (httpUtil::isMiniProgram()) {
|
|
|
+ $openId = $this->user['miniOpenId'];
|
|
|
+ } else {
|
|
|
+ $openId = $this->user['openId'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $typeList = configDict::getConfig('capitalType');
|
|
|
+ $capitalType = $typeList['xhOrder']['id'];
|
|
|
+ //将流水类型、代金劵传过去
|
|
|
+ $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType;
|
|
|
+
|
|
|
+ //订单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($this->frontUrl . '/notice/weixin-callback/');
|
|
|
+ $input->SetTrade_type("JSAPI");
|
|
|
+
|
|
|
+ //花卉宝代为申请的微信支付
|
|
|
+ $merchantExtend = $this->merchantExtend;
|
|
|
+ if ($merchantExtend['generalMerchant'] == 1) {
|
|
|
+ $input->SetSub_openid($openId);
|
|
|
+ } else {
|
|
|
+ $input->SetOpenid($openId);
|
|
|
+ }
|
|
|
+ //小程序使用miniAppId
|
|
|
+ if (httpUtil::isMiniProgram()) {
|
|
|
+ $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
+ $tools = new \JsApiPay();
|
|
|
+ $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
+ $newParams = json_decode($jsApiParameters, true);
|
|
|
+ //已请求微信不能修改价格
|
|
|
+ $updateData = [];
|
|
|
+ $updateData['modPrice'] = 0;
|
|
|
+ if (empty($order['deadline'])) {
|
|
|
+ $updateData['deadline'] = $expireTime;
|
|
|
+ }
|
|
|
+ OrderService::updateById($orderId, $updateData);
|
|
|
+ util::success($newParams);
|
|
|
+ }
|
|
|
+
|
|
|
+ //快捷付款订单
|
|
|
+ public function actionFastPay()
|
|
|
+ {
|
|
|
+ ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
|
|
|
+ $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->merchant);
|
|
|
+ //验证门店是否有效
|
|
|
+ $shopInfo = ShopService::getById($shopId);
|
|
|
+ ShopService::valid($shopInfo, $this->merchantId);
|
|
|
+ //门店订单
|
|
|
+ $sourceType = 1;
|
|
|
+ $post['userId'] = $this->userId;
|
|
|
+ $prePrice = round($post['prePrice'], 2);
|
|
|
+ $actPrice = $prePrice;
|
|
|
+ $post['actPrice'] = $actPrice;
|
|
|
+ $post['payStyle'] = 0;
|
|
|
+ $post['merchantId'] = $this->merchantId;
|
|
|
+ $now = time();
|
|
|
+ $expireTime = $now + 300;//订单5分钟后过期
|
|
|
+ $post['createTime'] = date("Y-m-d H:i:s", $now);
|
|
|
+ $post['deadline'] = $expireTime;
|
|
|
+ if ($actPrice <= 0) {
|
|
|
+ util::fail('请填写正确的金额');
|
|
|
+ }
|
|
|
+ //微信支付订单提交不能修改价格
|
|
|
+ $post['modPrice'] = $this->isWx ? 0 : 1;
|
|
|
+ $post['sourceType'] = $sourceType;
|
|
|
+ $order = OrderService::addOrder($post);
|
|
|
+ $orderId = $order['id'];
|
|
|
+ $orderSn = $order['orderSn'];
|
|
|
+ $merchantId = $this->merchantId;
|
|
|
+ $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
|
|
|
+
|
|
|
+ if ($payWay == 0) {
|
|
|
+ $orderId = $order['id'];
|
|
|
+ $name = '购买商品';
|
|
|
+ $totalFee = $actPrice;
|
|
|
+ $user = UserService::getById($this->userId);
|
|
|
+ $openId = isset($user['openId']) ? $user['openId'] : 0;
|
|
|
+ if (httpUtil::isMiniProgram()) {
|
|
|
+ //小程序使用miniOpenId
|
|
|
+ $openId = $user['miniOpenId'];
|
|
|
+ }
|
|
|
+ if (empty($openId)) {
|
|
|
+ util::fail('没有找到客户的openId');
|
|
|
+ }
|
|
|
+ $typeList = configDict::getConfig('capitalType');
|
|
|
+ $capitalType = $typeList['xhOrder']['id'];
|
|
|
+ $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
|
|
|
+ $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));//设置订单有效期5分钟
|
|
|
+ $input->SetNotify_url(Yii::$app->params['mHost'] . '/notice/wx-callback/');
|
|
|
+ $input->SetTrade_type("JSAPI");
|
|
|
+
|
|
|
+ //花卉宝代为申请的微信支付
|
|
|
+ $merchantExtend = $this->merchantExtend;
|
|
|
+ if ($merchantExtend['generalMerchant'] == 1) {
|
|
|
+ $input->SetSub_openid($openId);
|
|
|
+ } else {
|
|
|
+ $input->SetOpenid($openId);
|
|
|
+ }
|
|
|
+ //小程序使用miniAppId
|
|
|
+ if (httpUtil::isMiniProgram()) {
|
|
|
+ $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
+ }
|
|
|
+ $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
+ $tools = new \JsApiPay();
|
|
|
+ $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
+ $newParams = json_decode($jsApiParameters, true);
|
|
|
+ $newParams['orderId'] = $orderId;
|
|
|
+ util::success($newParams);
|
|
|
+
|
|
|
+ } elseif ($payWay == 1) {
|
|
|
+ if ($merchantId == 12358) {
|
|
|
+ $config = array(
|
|
|
+ //应用ID,您的APPID。
|
|
|
+ 'app_id' => "2019041663930158",
|
|
|
+ //商户私钥,您的原始格式RSA私钥
|
|
|
+ 'merchant_private_key' => "MIIEpAIBAAKCAQEA0NGNBMu5BkHU+ztmGhGdsJC1n2ZbXn4uoaYNni2eriPHJHG8vCWL1vv3W+gxX3twnmdQ57s3hFWfd5PIwMm+8QIwiPucckbmTEm2rC2g4j+UnUiXzICJWjlzlCWiBftrsctKKwjsZTPiuDJzUKmYRD4DYWy1+4Uh6k6x98qbALuiFFrh7esvsaSepZfQ+zBLzMVfrtPABkwEtOAzUL4hz4YW+EFfqyj3mu4LP4M+zBWSKRs0iCzJILG/7JA4OEkDJ89gGZ6LiaITUgffV2tg/IS81aNBfutb3tICBr1PLlKYCV0ois54kqmmP7anNrn/KRFI/k6iLd82e1HEoHhvDwIDAQABAoIBAQCr+PgPTAv8CDl0Ek4bCAj7AaJiPTTgVEDpJc0vSNjXB2YZMIZD2RQaoHXtvgLzZMCx49pwjfHBzZZAL3h0tXHIIIqCNd15C8TcbRTBJe7KhZxKEB/b7ruvj4MNLhUKoi3mRcq2OGofSqTcF8h6VMGu6fd0w8f39YOh6N+Od9BBv8aL7CtBwQQihzatBdr2CyjH50TmlVWfEz2YKoZBGRuMy7EzLZgmR5IzEJC36tOBAg5DORNkEMAuzvnmBQznZCtzMZHW5Ytlh/3kbCUMsrWL6ioox/mel4DoQNnQ1kZ60f7Gny3I+0HiJ+vxVBZ3Nyd8FCVbAlq6avkB3ZGoCx0xAoGBAP/Mhf8X81mLK80TQsSWYPmnjnYkOZ7vIpNc/b6/N+BKAAjWB+0wXJ73nhuzB8cuJBz6TK8RE2uUuiUbiVP1jkrQ2EoCWadndKE1fcLFSSOYlN9rxfINcLicdNAFYu0m8He5cqPpW+06sD8HGOlWeBOyPvitXBjBeOB9dPWBpVkpAoGBAND7kruod1T4ErtOavYv4ErlyN0O6PpQR3MBlnzXnJfKLdaMvc/JaqjZtk14Nl9RnBDzN6d93LHxariyuTHw9mdGAPOpxcUEsUdOw56eRIzhyY8lz0c+lvE32r2NypuzK/2BGP5xR+spe7D4esuhLQhUYjByTWbgLQD+7724QrV3AoGAYuO2ib/AnEVpUYa4sTdRljJoqNOoUwEv5Lh2gF98QoFZMhFMTy37IJmpzhuQTjhQTcOWEbgQQe7lZ6MVnBe6QsIqW7I85rLgK9J6I+oRNGmwZA9OHx2DDlut7R2n+Pas0BwpbaSxnSyrJjKgNtTu5u5p2clraUaibGcT6DWOrsECgYEAspjM5aMrmGoJWBnEP3Da9ic6afD8Gi/RX+/TdA2vvekDE4BkFtfDV1n3+mzpyrwr7DBvN6zQlyICWqYirxOHAOtKlPJaGe3Qs2gUtdH8M4oifzuI0RIkXTGmtqgepsGQrq1NduXI2KgzFSLFjpDHs36qC00j6O9chqVYrYJzQDECgYBQyIWx3BBEUgWCbLTT8QeUdf+EnZSLZzIIQFn88zImhqkTSMbpBmcZpI4oOlWiM8i4XOaEzu+EDFIRAchIbVlDgBV1OprAN5BAez03oyh1JkCDYrsEj7FMqWSmbxiY2uubPshMLEGdPU+I46oJTO6FzMyG6hnQrK+/ne0zH8A5LA==",
|
|
|
+ //异步通知地址
|
|
|
+ 'notify_url' => Yii::$app->params['frontUrl'] . "/notice/alipay-async",
|
|
|
+ //同步跳转
|
|
|
+ 'return_url' => "",
|
|
|
+ //编码格式
|
|
|
+ 'charset' => "UTF-8",
|
|
|
+ //签名方式
|
|
|
+ 'sign_type' => "RSA2",
|
|
|
+ //支付宝网关
|
|
|
+ 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
|
|
|
+ //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
|
|
|
+ 'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkFYqNkoWJIx37fGcUBbnZJ+APf14YHO1cBdp9RFSasxj9gm+pwbtK3J6uRuPygK0K/OCgvtuFJ6mZT3tNUEgSZMjnre5Z7IzQnzIBUYFPUEO85s+/RDr5HnAqgOIbu9GL8GWrU6g6uj+QmW591vXckmsbujPx0S3IP+TMOQZWA0JVvDu+T9yGfv3pacKUgdNvYnas/si3278TL4DeIVjZ4OmbbEPmEhD/OhSVlTSWEOdqLuV4DvEpmrGa8XoyfFEtgV9qSVb454Qwu5Nw/ATc9+ssMbN6ROXzOQbAAfqAe6riNUtKEHGVaCynfUAYNyR6yvJb8+VkMR02nBEDC9QHQIDAQAB",
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ $config = array(
|
|
|
+ //应用ID,您的APPID。
|
|
|
+ 'app_id' => "2017041906821571",
|
|
|
+ //商户私钥,您的原始格式RSA私钥
|
|
|
+ 'merchant_private_key' => "MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8dOBKWRRKsHBnlUbPrXV4FcFDeLm0fPfd+iZ/2AaZ1+ix962f3BpYIiq7+f9zaMRazfnw9L8x31pByyMktLs12EkoQ0dHsMxxUzzKAOiiPnvCn8Pv+Jb2qej8GXgCjefutCVNMWGsdwJtMVXEbpdmMa48Wvw+0In5ZS/UG39YAreFzgDqI9jWHE1ZhkGmB1+8hKpeIlEeVGAeYVveUgssMORdA/YY8SWHk26KSIFXBrmdKjAcRJ8Q7ZHUmzIqAV+IMV+RD4J5mZHeJgdAECgYEA8J+Hp1M6eYbT4CPLXa//yRP6Xo+qSzrKHaRB1LRAjYhvKpx/TQetYpNCJ5bWpa+Jp0T5R21pzuYaJkPuGlNEHA13b5T3r1l2ltomSEdaShvD5EZ9WtErYV5zpSv7FjjIGkbwa0H3A8Ydnvw5z4A9TZjjHLjC2GtVGJReqHGglMECgYEAydddA4NRPxmXvIjjmLb1Ft1qwHuyv3vvWhi50foGZXNEnBcfP/OkfyBDDpOEu34GZBMXK9ykHBs1l93OEFGXh7AwW0Lp5lARahBEfBZgPjq5yPO8TOJZrb5hVcuvoDdGjxpRh93XDnQDhWS/1IvUcBLcIsTcnVvfrkX4NLxF/W0CgYEAxamG+gD4rBQBwMImsRN+/2MV7M//iEUG+0qPeXeI/7rv9wUP3etMlwl48qSKNxj37xxN2ksa/Acxu/VZhu6XqKO3VUX+IWFQdaNGh2F13iLozIDLQOtKw3WfcjOq0xpZ5pwXq0RI8iSw+IUhyD8EHNZW2qU8CiRBhyt6hsywqQECgYBa8+06FAachI/XqWfF/UvcDdJ5AkS9/L8SvmmdsSkItjSIkfLHAqdxkbwl6Vu6kUOX/PJIFZjuAWTZFl4xBFNgFYj01uZHnnT6cnIp6HteD2CAqTSFAMqgfFWoL6zoaYAmJBnxO4oZPTYI+ilnQcts5VLFaChx0GCvS2BZgy2W0QKBgQDjP2VtRq4aVSLUq2z1KIDI7GJBbOM5KSW1OEj4sfEdViozPh3Ar/FQWiij1oCZF+iJdKkonHoDbDd+Q0ykcpQ+5Gv07iiT8wJYFR/0j8g2kfql7bVQhGSBeBMS5sawKR3CvkfW73WX+CNnf0PklTY0kTyt6WRXDnKSeyxFVwSZ7g==",
|
|
|
+ //异步通知地址
|
|
|
+ 'notify_url' => Yii::$app->params['frontUrl'] . "/notice/alipay-async",
|
|
|
+ //同步跳转
|
|
|
+ 'return_url' => "",
|
|
|
+ //编码格式
|
|
|
+ 'charset' => "UTF-8",
|
|
|
+ //签名方式
|
|
|
+ 'sign_type' => "RSA2",
|
|
|
+ //支付宝网关
|
|
|
+ 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
|
|
|
+ //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
|
|
|
+ 'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsz3m9juAR1xew4DY6c34gvbwNg8pZ92f932tseKs+4+pF0e+jTDiUo/xHImNDi1KXt1B+s3LxY9L/sxEksbavwmhgbz/igN1cAEwS2YM+Gnf0csDrxAPJhoKL5FTwxPEQ/8VSgroU+6GlF3LAx4VHa1qfn5MqRPfLroJcyPDyGfNe9vna2FnO4E/PH+hVbvPUAwX3XrUvJIm4OgY0JE3HYFlu+O7F4Ln6+Sl+Zv/ZE2nZAvNiyAwW5iVKhKXLieExqwd0NdrP28baBqkkIY+tmV7butGjB52iK1UbU0+1uiaPL4xBxRy6d0LZmYlvdVHp0JRUuwxBLChGgOCo/76DQIDAQAB",
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $alipayWap = Yii::getAlias("@vendor/alipayWap");
|
|
|
+ require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
|
|
|
+ require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
|
|
|
+
|
|
|
+ $totalFee = $order['actPrice'];
|
|
|
+ $out_trade_no = $orderId;//商户订单号,商户网站订单系统中唯一订单号,必填
|
|
|
+ $subject = '购买商品';//订单名称,必填
|
|
|
+ $total_amount = $totalFee;//付款金额,必填
|
|
|
+ $body = '';//商品描述,可空
|
|
|
+ $timeout_express = "1m";//超时时间
|
|
|
+
|
|
|
+ $typeList = configDict::getConfig('capitalType');
|
|
|
+ $capitalType = $typeList['xhOrder']['id'];
|
|
|
+ $passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
|
|
|
+ $passbackParams = urlencode($passbackParams);
|
|
|
+
|
|
|
+ $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
|
|
|
+ $payRequestBuilder->setBody($body);
|
|
|
+ $payRequestBuilder->setSubject($subject);
|
|
|
+ $payRequestBuilder->setOutTradeNo($out_trade_no);
|
|
|
+ $payRequestBuilder->setTotalAmount($total_amount);
|
|
|
+ $payRequestBuilder->setTimeExpress($timeout_express);
|
|
|
+ //在异步通知时将该参数原样返回
|
|
|
+ $payRequestBuilder->setPassbackParams($passbackParams);
|
|
|
+ //同步通知
|
|
|
+ $returnUrl = Yii::$app->params['frontUrl'] . "/notice/pay-alipay-sync";
|
|
|
+ //异步通知
|
|
|
+ $notifyUrl = Yii::$app->params['frontUrl'] . "/notice/alipay-async";
|
|
|
+ $payResponse = new \AlipayTradeService($config);
|
|
|
+ $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
|
|
|
+ util::success($result);
|
|
|
+
|
|
|
+ } elseif ($payWay == 2) {
|
|
|
+ //验证支付密码是否正确
|
|
|
+ $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
|
|
|
+ UserService::validPayPassword($payPassword, $this->user);
|
|
|
+ $typeList = configDict::getConfig('capitalType');
|
|
|
+ $capitalType = $typeList['xhOrder']['id'];
|
|
|
+ $totalFee = $order['actPrice'];
|
|
|
+ xhPayToolService::balancePay($orderSn, $totalFee, $capitalType, $couponId);
|
|
|
+ util::success(['discountAmount' => 9.9, 'discountType' => 0]);
|
|
|
+ } else {
|
|
|
+ util::fail('无效的支付方式');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单列表 shish 2019.12.12
|
|
|
+ public function actionList()
|
|
|
+ {
|
|
|
+ $where = ['userId' => $this->userId];
|
|
|
+ $list = OrderService::getOrderList($where);
|
|
|
+ util::success($list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单评价
|
|
|
+ public function actionComment()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $id = $post['id'];
|
|
|
+ $order = OrderService::getById($id);
|
|
|
+ if ($this->userId != $order['userId']) {
|
|
|
+ util::fail('您没有权限操作');
|
|
|
+ }
|
|
|
+ OrderService::comment($post);
|
|
|
+ util::ok('提交成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单详情 shish 2019.12.16
|
|
|
+ public function actionDetail()
|
|
|
+ {
|
|
|
+ $id = Yii::$app->request->get('id', 0);
|
|
|
+ $orderSn = Yii::$app->request->get('orderSn', '');
|
|
|
+ $detail = [];
|
|
|
+ if (!empty($id)) {
|
|
|
+ $detail = OrderService::getOrderById($id);
|
|
|
+ }
|
|
|
+ if (!empty($orderSn)) {
|
|
|
+ $detail = OrderService::getOrderBySn($orderSn);
|
|
|
+ }
|
|
|
+ OrderService::valid($detail, $this->merchantId);
|
|
|
+ util::success($detail);
|
|
|
+ }
|
|
|
+
|
|
|
}
|