shish před 6 roky
rodič
revize
5716a87c70

+ 482 - 0
app/client/controllers/OrderController.php

@@ -0,0 +1,482 @@
+<?php
+
+namespace client\controllers;
+
+use biz\goods\services\CategoryService;
+use biz\goods\services\GoodsCategoryService;
+use Yii;
+use yii\web\Controller;
+use common\components\util;
+
+class OrderController extends BaseController
+{
+
+	//商城下单操作 shish 2019.12.3
+	public function actionCreateOrder()
+	{
+		$post = Yii::$app->request->post();
+		//dump($post);die;
+		$userId = $this->userId;
+		$post['userId'] = $userId;
+		$post['payWay'] = $this->isWeixin == true ? 0 : 1;
+		$lat2 = $post['receiveLat'];//收货人纬度
+		$lng2 = $post['receiveLong'];//收货人经度
+		$lat1 = $this->merchant['shopLat'];//花店纬度
+		$lng1 = $this->merchant['shopLong'];//花店经度
+		$calcDistance = util::getDistance($lat1, $lng1, $lat2, $lng2);//防止别人改动,PHP计算的距离会比腾讯js算的小,但能保证有一定准确性
+		$post['sendDistance'] = $post['sendDistance'] >= $calcDistance ? $post['sendDistance'] : $calcDistance;//二地距离
+		$sendDistance = $post['sendDistance'];
+		$freight = configDict::getConfig('freight');
+		$firstDistance = $freight['firstDistance'];
+		$firstPrice = $freight['firstPrice'];
+		$nextDistance = $freight['nextDistance'];
+		$nextPrice = $freight['nextPrice'];
+		if ($sendDistance <= $firstDistance && $post['isCharge'] == 1) {
+			$post['sendCost'] = $firstPrice;
+		} else if ($post['isCharge'] == 1) {
+			$subDistance = $sendDistance - $firstDistance;
+			$addPrice = intval($subDistance / $nextDistance) * $nextPrice;
+			$post['sendCost'] = $firstPrice + $addPrice;
+		}
+		if (empty($this->merchantExtend['payment'])) {
+			util::fail('支付功能未开通,暂时无法购买哦~');
+		}
+		$couponAmount = 0;
+		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;//代金劵
+		if (!empty($couponId)) {
+			$coupon = xhCouponService::getById($couponId);
+			$couponUserId = $coupon['userId'];
+			if ($couponUserId != $userId) {
+				util::fail('不是你的代金劵');
+			}
+			if ($coupon['useStatus'] == 1 || $coupon['deadline'] < time()) {
+				util::fail('代金劵已经失效了');
+			}
+			$couponAmount = $coupon['amount'];
+		}
+		//不要将代金劵保存到订单表,付款成功后再保存进去!!!
+		unset($post['couponId']);
+		$post['merchantId'] = $this->merchantId;
+		//店铺id
+		$post['shopId'] = $this->merchant['defaultShopId'];
+		$order = xhOrderService::add($post);//创建订单
+		if ($order == false) {
+			util::fail('创建订单失败');
+		}
+		$orderId = $order['id'];
+		$oData = [];
+		$goodsInfo = $post['goodsInfo'];
+		$totalFee = 0;//计算总价格
+		$goodsIdList = [];
+		$multiPriceIdList = [];
+		$orderName = '';
+		$goodsNum = 0;
+		foreach ($goodsInfo as $key => $val) {
+			$multiPriceId = 0;//多种价格表Id
+			$goodsId = $val['goodsId'];
+			$num = $val['num'];
+			$goodsNum += $num;
+			$goods = xhGoodsService::getById($goodsId);
+			if (empty($orderName)) {
+				$orderName = $goods['goodsName'];
+			}
+			$price = $goods['price'];
+			if ($val['multiPriceId'] != 0 && $goods['multiPrice'] != '') {
+				$pos = strpos($goods['multiPrice'], $val['multiPriceId']);
+				if ($pos === false) {
+					util::fail('订单的商品不存在');
+				}
+				$goodPrice = xhGoodsPriceService::getById($val['multiPriceId']);
+				
+				//$price = $goodPrice['price'];
+				$price = xhGoodsSettingService::changePrice($goods, $goodPrice['price']);//统一对商品进行价格等方面设置
+				//多种价格规格 替换 默认(单价格)
+				$goods['goodsName'] = $goodPrice['title'];
+				//$goods['cover'] = $goodPrice['picture'];//后台图片上传功能未开发,暂时使用默认商品图片
+				$multiPriceId = $val['multiPriceId'];
+			}
+			$totalFee += $price * $num;
+			$goodsIdList[] = $goodsId;
+			$multiPriceIdList[] = $multiPriceId;
+			$data = [
+				'orderId' => $orderId,
+				'goodsId' => $goodsId,
+				'userId' => $userId,
+				'merchantId' => $this->merchantId,
+				'title' => $goods['goodsName'],
+				'cover' => $goods['cover'],
+				'unitPrice' => $price,
+				'num' => $num,
+				'multiPriceId' => $multiPriceId,
+				'createTime' => date("Y-m-d H:i:s"),
+			];
+			xhOrderGoodsService::add($data);//创建订单商品列表
+		}
+		$sendCost = $post['sendCost'];//运费
+		$oData['goodsNum'] = $goodsNum;//订单的商品数量类型,单个还是多个的
+		$oData['prePrice'] = $totalFee + $sendCost;
+		$oData['orderName'] = $goodsNum > 1 ? $orderName . '等' . $goodsNum . '件商品' : $orderName;
+		if (isset($post['sourceType']) && $post['sourceType'] == 'cart') {
+			if (!empty($goodsIdList)) {
+				foreach ($goodsIdList as $key => $goodsId) {
+					xhCartService::delByIds($userId, $goodsId, $multiPriceIdList[$key]);//删除购物车($userId, $goodsId, $goodsPriceId, $cartId)
+				}
+			}
+		}
+		$userAsset = xhUserAssetService::getByUserId($userId);
+		$level = $userAsset['memberLevel'];
+		if ($level > 0) {
+			$gradeList = xhMerchantExtendService::getGradeList($this->merchantExtend);
+			$discount = $gradeList[$level]['discount'];
+			$discount = strlen($discount) == 1 ? $discount * 10 : $discount;
+			$totalFee = number_format($discount * $totalFee / 100, 2);
+		}
+		$oData['actPrice'] = $totalFee + $sendCost - $couponAmount;
+		xhOrderService::updateById($orderId, $oData);
+		util::successInfo('订单创建成功', 'A0001', ['orderId' => $orderId, 'couponId' => $couponId]);
+	}
+
+	//获取商城下单要用的微信支付参数 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;
+		$now = time();
+		$expireTime = $now + 1800;//订单30分钟后过期
+		if ($this->merchantExtend['payment'] == 0) {
+			util::fail('还没开通支付功能哟');
+		}
+		$orderId = isset($post['orderId']) ? $post['orderId'] : 0;
+		$order = xhOrderService::getById($orderId);
+		if (!empty($couponId)) {
+			$coupon = xhCouponService::getById($couponId);
+			if ($coupon['useStatus'] == 1 || $now > $coupon['deadline']) {
+				util::fail('代金劵已经失效');
+			}
+			if ($coupon['meetAmount'] > $order['prePrice']) {
+				util::fail('消费金额不足' . $coupon['meetAmount'] . '元');
+			}
+		}
+		if ($order['userId'] != 0 && $order['userId'] != $this->userId) {//当 快速下单时,字段userId为0(未保存指定用户);用户操作后,就只能该用户访问
+			util::fail('非法访问');
+		}
+		if (!empty($order['deadline']) && $now > $order['deadline']) {
+			util::fail('订单已经过期');
+		}
+		if (ceil($order['actPrice']) <= 0) {
+			util::fail('消费金额小于(等于)0');
+		}
+		$name = $order['orderName'];
+		$totalFee = $order['actPrice'];
+		$openId = $this->user['openId'];
+		$typeList = configDict::getConfig('capitalType');
+		$capitalType = $typeList['xhOrder']['id'];
+		$attach = "couponId=" . $couponId . "&capitalType=" . $capitalType;//将流水类型、代金劵传过去
+		
+		$weixin = Yii::getAlias("@vendor/weixin");
+		require_once($weixin . '/lib/WxPay.Api.php');
+		require_once($weixin . '/example/WxPay.JsApiPay.php');
+		$input = new \WxPayUnifiedOrder();
+		$input->SetBody($name);
+		$input->SetOut_trade_no($orderId);
+		$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");
+		
+		//服务商 代设置微信支付,要添加的参数设置
+		if ($this->merchantExtend['generalMerchant'] == 1) {
+			//$input->SetOpenid($openId);
+			$input->SetSub_openid($openId);
+			//自设置 微信支付
+		} else {
+			$input->SetOpenid($openId);
+		}
+		
+		$wxOrder = \WxPayApi::unifiedOrder($input, 6, $this->merchantExtend);
+		$tools = new \JsApiPay();
+		$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $this->merchantExtend);
+		$newParams = json_decode($jsApiParameters, true);
+		
+		$updateData = ['modPriceStatus' => 1];//已经请求微信不能修改价格
+		if (empty($order['deadline'])) {
+			$updateData['deadline'] = $expireTime;
+		}
+		xhOrderService::updateById($orderId, $updateData);//已经请求微信不能修改价格
+		util::successInfo('操作成功', 'A0001', $newParams);
+	}
+	
+	/**
+	 * 订单 - 支付宝支付
+	 */
+	public function actionZfbPay()
+	{
+		header("Content-type: text/html; charset=utf-8");
+		$alipayWap = Yii::getAlias("@vendor/alipayWap");
+		require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
+		require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
+		require_once($alipayWap . '/config.php');
+		
+		$get = Yii::$app->request->get();
+		$orderId = isset($get['orderId']) ? $get['orderId'] : 0;
+		$couponId = isset($get['couponId']) ? $get['couponId'] : 0;
+		$orderData = xhOrderService::getById($orderId);
+		$waitForPay = configDict::getConfig('payStatus', 'waitForPay');
+		if ($orderData['payStatus'] != $waitForPay) {
+			echo '已经支付成功';
+			util::end();
+		}
+		$merchantId = $orderData['merchantId'];
+		$out_trade_no = $orderId;//商户订单号,商户网站订单系统中唯一订单号,必填
+		$subject = $orderData['orderName'];//订单名称,必填
+		$total_amount = $orderData['actPrice'];;//付款金额,必填
+		$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/order-alipay-sync";
+		$payResponse = new \AlipayTradeService($config);
+		$result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $config['notify_url']);
+		$this->renderPartial('alipay', ['result' => $result]);
+	}
+	
+	//快速付款订单
+	public function actionFastCreateOrder()
+	{
+		ini_set('date.timezone', 'Asia/Shanghai');
+		$post = Yii::$app->request->post();
+		$payWay = isset($post['payWay']) ? $post['payWay'] : '';
+		$shopId = isset($post['shopId']) ? $post['shopId'] : 0;
+		//来源 0自建商城 1门店 2微信朋友圈 3淘宝
+		$sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
+		
+		$shopInfo = xhShop::find()->where(['id' => $shopId])->one();
+		if (empty($shopInfo) || $shopInfo->merchantId != $this->merchantId) {
+			util::fail('门店无效');
+		}
+		
+		unset($post['_csrf']);
+		unset($post['payWay']);
+		$post['userId'] = $this->userId;
+		$prePrice = round($post['prePrice'], 2);//四舍五入,保留二位小数
+		
+		$userAsset = xhUserAssetService::getByUserId($this->userId);
+		$level = isset($userAsset['memberLevel']) ? $userAsset['memberLevel'] : 0;
+		$merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
+		$memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
+		Yii::info(json_encode($merchantExtend));
+		Yii::info(json_encode($memberIntegral));
+		$discount = isset($memberIntegral[$level]['discount']) ? $memberIntegral[$level]['discount'] : $memberIntegral[$level]['discount'];
+		$actPrice = $prePrice;
+		$couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
+		Yii::info($this->userId . ' ' . $level . ' ' . $discount);
+		//没有优惠券才能使用会员折扣 shish 2019.8.30
+		if (!empty($discount) && $prePrice >= 1 && empty($couponId)) {
+			$currentPrice = ($prePrice * $discount) / 100;
+			$actPrice = substr(sprintf("%.3f", $currentPrice), 0, -2);
+		}
+		//没有优惠卷,微信朋友圈付款才给随机优惠金额 shish 2019.9.12
+		if ($sourceType == 2 && empty($couponId)) {
+			$discountAmount = OrderService::getRandDiscount($actPrice);
+			//测试环境直接随机优惠0.01
+			if (isset(Yii::$app->params['merchant'])) {
+				$merchant = Yii::$app->params['merchant'];
+				if ($merchant['merchantName'] == '花美灵') {
+					$discountAmount = 0.01;
+				}
+			}
+			$actPrice = stringUtil::calcSub($actPrice, $discountAmount);
+			$post['discountType'] = 2;//优惠类型是:付款随机优惠
+			$post['discountAmount'] = $discountAmount;
+		}
+		$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 (!empty($couponId)) {
+			$time = time();
+			$coupon = CouponService::getById($couponId);
+			if ($coupon['deadline'] <= $time) {
+				util::fail('优惠卷已经过期');
+			}
+			if ($coupon['status'] == 1) {
+				util::fail('优惠卷已经使用');
+			}
+			if ($coupon['meetAmount'] > $post['prePrice']) {
+				util::fail('消费金额不足' . $coupon['meetAmount'] . '元');
+			}
+			$post['actPrice'] = stringUtil::calcSub($post['prePrice'], $coupon['amount']);//浮点相减
+			$post['discountAmount'] = $coupon['amount'];
+			$post['discountType'] = 0;
+		}
+		if ($post['actPrice'] <= 0) {
+			util::fail('消费金额太低');
+		}
+		if ($this->isWeixin) {
+			$post['modPriceStatus'] = 1;//微信已经提交不能再修改价格
+		}
+		$post['sourceType'] = $sourceType;
+		$post['id'] = stringUtil::generateOrderNo($this->merchantId, $this->userId);
+		$payment = xhOrderService::add($post);
+		$orderId = $payment['id'];
+		
+		if ($payWay == 'balance') {//余额支付
+			util::successInfo('操作成功', 'A0001', ['orderId' => $orderId]);
+		}
+		$name = '购买商品';
+		$totalFee = $post['actPrice'];
+		if ($this->isWeixin) {
+			$userId = $post['userId'];
+			$user = xhUserService::getById($userId);
+			if ($user['merchantId'] != $this->merchantId) {
+				util::fail('非法用户');
+			}
+			$openId = $user['openId'];
+			$typeList = configDict::getConfig('capitalType');
+			$capitalType = $typeList['xhOrder']['id'];
+			$attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
+			$weixin = Yii::getAlias("@vendor/weixin");
+			require_once($weixin . '/lib/WxPay.Api.php');
+			require_once($weixin . '/example/WxPay.JsApiPay.php');
+			$input = new \WxPayUnifiedOrder();
+			$input->SetBody($name);
+			$input->SetOut_trade_no($orderId);
+			$input->SetTotal_fee($totalFee * 100);
+			$input->SetTime_start(date("YmdHis", $now));
+			$input->SetAttach($attach);
+			$input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟
+			$input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
+			$input->SetTrade_type("JSAPI");
+			
+			
+			//服务商 代设置微信支付,要添加的参数设置
+			if ($this->merchantExtend['generalMerchant'] == 1) {
+				//$input->SetOpenid($openId);
+				$input->SetSub_openid($openId);
+				//自设置 微信支付
+			} else {
+				$input->SetOpenid($openId);
+			}
+			
+			$wxOrder = \WxPayApi::unifiedOrder($input, 6, $this->merchantExtend);
+			$tools = new \JsApiPay();
+			$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $this->merchantExtend);
+			$newParams = json_decode($jsApiParameters, true);
+			$newParams['orderId'] = $orderId;
+			util::successInfo('操作成功', 'A0001', $newParams);
+		}
+		util::successInfo('操作成功', 'A0001', ['orderId' => $orderId]);
+	}
+
+	//快捷支付使用支付宝付款 shish 2019.12.3
+	public function actionFastZfbPay()
+	{
+		header("Content-type: text/html; charset=utf-8");
+		$get = Yii::$app->request->get();
+		$orderId = isset($get['orderId']) ? $get['orderId'] : 0;
+		$couponId = isset($get['couponId']) ? $get['couponId'] : 0;
+		$pay = xhOrderService::getById($orderId);
+		$merchantId = $pay['merchantId'];
+		
+		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');
+		//require_once($alipayWap . '/config.php');
+		
+		
+		$totalFee = $pay['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);
+		$this->renderPartial('execAlipay', ['result' => $result]);
+	}
+
+}

+ 134 - 399
app/client/controllers/PayController.php

@@ -28,122 +28,136 @@ use common\components\configDict;
 
 class PayController extends BaseController
 {
-	public $layout = 'centerMain';
-	public $withoutLogin = ['success', 'exec-alipay', 'detail', 'get-params', 'receive-success', 'not-login-receive-info', 'not-login-save-receive-info'];
-	
+
+	public $withoutLogin = ['get-params'];
+
 	public $enableCsrfValidation = false;
-	
-	public function actionIndex()
-	{
-		$request = Yii::$app->request;
-		$id = $request->get('shopId', 0);
-		$sourceType = Yii::$app->request->get('sourceType', 1);//默认1门店
-		if (empty($id)) {
-			util::fail('没有门店');
-		}
-		$userInfo = [];
-		$userAsset = [];
-		$userId = 0;
-		$level = 0;
-		$discount = 0;
-		if ($this->isLogin) {
-			$userInfo = $this->user;
-			$userId = $this->userId;
-			$userAsset = xhUserAssetService::getByUserId($userId);
-			$level = isset($userAsset['memberLevel']) ? $userAsset['memberLevel'] : 0;
-			$merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
-			$memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
-			$discount = isset($memberIntegral[$level]['discount']) ? $memberIntegral[$level]['discount'] : $memberIntegral[$level]['discount'];
-		}
-		$usageList = UsageRelationService::getMyUsage();
-		$categoryList = CategoryRelateService::getCategoryData();
-		$hasCoupon = CouponService::hasCoupon();
-		return $this->renderPartial('index', [
-			'shopId' => $id,
-			'userAsset' => $userAsset,
-			'userInfo' => $userInfo,
-			'userId' => $userId,
-			'level' => $level,
-			'discount' => $discount,
-			'usageList' => $usageList,
-			'categoryList' => $categoryList,
-			'hasCoupon' => $hasCoupon,
-			'sourceType' => $sourceType,
-		]);
-	}
-	
-	public function actionSuccess()
-	{
-		$get = Yii::$app->request->get();
-		$orderId = isset($get['orderId']) ? $get['orderId'] : 0;
-		$payment = OrderService::getById($orderId, true);
-		if (empty($payment)) {
-			util::failInfo('订单号未找到');
-		}
-		if ($payment->merchantId != $this->merchantId) {
-			util::stop('非法访问');
-		}
-		$payWay = configDict::getConfig('payWayFullName');
-		/**确认是否可以领卷**/
-		$userId = $payment->userId;
-		$payCallback = $payment->payStatus == 1 ? true : false;
-		$flag = UserAssetService::couldGetCoupon($userId, $payCallback);
-		Yii::info('flag:' . $flag);
-		$imgUrl = '';
-		if ($flag != -1) {
-			if (empty($payment->getCouponQrCode)) {
-				$url = WxSceneService::generatePayGetCouponScene($userId);
-				$logo = Yii::getAlias("@app") . '/../images' . $this->merchant['logo'];
-				$imgUrl = qrCodeUtil::generate($url, 'pay_get_coupon_url_' . date("YmdH") . '_' . $this->merchantId . '_' . $userId, $logo);
-				$payment->getCouponQrCode = $imgUrl;
-				$payment->save();
-			} else {
-				$imgUrl = $payment->getCouponQrCode;
-			}
-		}
-		return $this->renderPartial('success', ['payment' => $payment, 'payWay' => $payWay, 'flag' => $flag, 'imgUrl' => $imgUrl]);
-	}
-	
-	/**
-	 * 支付订单明细
-	 */
-	public function actionDetail()
+
+	//创建订单 shish 2019.12.3
+	public function actionCreateOrder()
 	{
-		$get = Yii::$app->request->get();
-		$orderId = isset($get['orderId']) ? $get['orderId'] : 0;
-		$payment = xhOrderService::getById($orderId);
-		if ($payment['merchantId'] != $this->merchantId) {
-			util::stop('非法访问');
-		}
-		$payWay = configDict::getConfig('payWayFullName');
-		$couponId = $payment['couponId'];
-		$coupon = [];
+		$post = Yii::$app->request->post();
+		//dump($post);die;
+		$userId = $this->userId;
+		$post['userId'] = $userId;
+		$post['payWay'] = $this->isWeixin == true ? 0 : 1;
+		$lat2 = $post['receiveLat'];//收货人纬度
+		$lng2 = $post['receiveLong'];//收货人经度
+		$lat1 = $this->merchant['shopLat'];//花店纬度
+		$lng1 = $this->merchant['shopLong'];//花店经度
+		$calcDistance = util::getDistance($lat1, $lng1, $lat2, $lng2);//防止别人改动,PHP计算的距离会比腾讯js算的小,但能保证有一定准确性
+		$post['sendDistance'] = $post['sendDistance'] >= $calcDistance ? $post['sendDistance'] : $calcDistance;//二地距离
+		$sendDistance = $post['sendDistance'];
+		$freight = configDict::getConfig('freight');
+		$firstDistance = $freight['firstDistance'];
+		$firstPrice = $freight['firstPrice'];
+		$nextDistance = $freight['nextDistance'];
+		$nextPrice = $freight['nextPrice'];
+		if ($sendDistance <= $firstDistance && $post['isCharge'] == 1) {
+			$post['sendCost'] = $firstPrice;
+		} else if ($post['isCharge'] == 1) {
+			$subDistance = $sendDistance - $firstDistance;
+			$addPrice = intval($subDistance / $nextDistance) * $nextPrice;
+			$post['sendCost'] = $firstPrice + $addPrice;
+		}
+		if (empty($this->merchantExtend['payment'])) {
+			util::failInfo('支付功能未开通,暂时无法购买哦~');
+		}
+		$couponAmount = 0;
+		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;//代金劵
 		if (!empty($couponId)) {
 			$coupon = xhCouponService::getById($couponId);
+			$couponUserId = $coupon['userId'];
+			if ($couponUserId != $userId) {
+				util::failInfo('不是你的代金劵');
+			}
+			if ($coupon['useStatus'] == 1 || $coupon['deadline'] < time()) {
+				util::failInfo('代金劵已经失效了');
+			}
+			$couponAmount = $coupon['amount'];
 		}
-		return $this->renderPartial('detail', ['payment' => $payment, 'payWay' => $payWay, 'coupon' => $coupon]);
-	}
-	
-	public function actionBalancePay()
-	{
-		$post = Yii::$app->request->post();
-		$orderId = isset($post['orderId']) ? $post['orderId'] : 0;
-		$payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
-		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;
-		$order = xhOrderService::getById($orderId);
-		if (empty($order) || $order['userId'] != $this->userId) {
-			util::failInfo('订单资料不合法');
-		}
-		if ($this->user['payPassword'] != md5($payPassword)) {
-			util::failInfo('密码错误 ');
+		//不要将代金劵保存到订单表,付款成功后再保存进去!!!
+		unset($post['couponId']);
+		$post['merchantId'] = $this->merchantId;
+		//店铺id
+		$post['shopId'] = $this->merchant['defaultShopId'];
+		$order = xhOrderService::add($post);//创建订单
+		if ($order == false) {
+			util::failInfo('创建订单失败');
+		}
+		$orderId = $order['id'];
+		$oData = [];
+		$goodsInfo = $post['goodsInfo'];
+		$totalFee = 0;//计算总价格
+		$goodsIdList = [];
+		$multiPriceIdList = [];
+		$orderName = '';
+		$goodsNum = 0;
+		foreach ($goodsInfo as $key => $val) {
+			$multiPriceId = 0;//多种价格表Id
+			$goodsId = $val['goodsId'];
+			$num = $val['num'];
+			$goodsNum += $num;
+			$goods = xhGoodsService::getById($goodsId);
+			if (empty($orderName)) {
+				$orderName = $goods['goodsName'];
+			}
+			$price = $goods['price'];
+			if ($val['multiPriceId'] != 0 && $goods['multiPrice'] != '') {
+				$pos = strpos($goods['multiPrice'], $val['multiPriceId']);
+				if ($pos === false) {
+					util::failInfo('订单的商品不存在');
+				}
+				$goodPrice = xhGoodsPriceService::getById($val['multiPriceId']);
+				
+				//$price = $goodPrice['price'];
+				$price = xhGoodsSettingService::changePrice($goods, $goodPrice['price']);//统一对商品进行价格等方面设置
+				//多种价格规格 替换 默认(单价格)
+				$goods['goodsName'] = $goodPrice['title'];
+				//$goods['cover'] = $goodPrice['picture'];//后台图片上传功能未开发,暂时使用默认商品图片
+				$multiPriceId = $val['multiPriceId'];
+			}
+			$totalFee += $price * $num;
+			$goodsIdList[] = $goodsId;
+			$multiPriceIdList[] = $multiPriceId;
+			$data = [
+				'orderId' => $orderId,
+				'goodsId' => $goodsId,
+				'userId' => $userId,
+				'merchantId' => $this->merchantId,
+				'title' => $goods['goodsName'],
+				'cover' => $goods['cover'],
+				'unitPrice' => $price,
+				'num' => $num,
+				'multiPriceId' => $multiPriceId,
+				'createTime' => date("Y-m-d H:i:s"),
+			];
+			xhOrderGoodsService::add($data);//创建订单商品列表
+		}
+		$sendCost = $post['sendCost'];//运费
+		$oData['goodsNum'] = $goodsNum;//订单的商品数量类型,单个还是多个的
+		$oData['prePrice'] = $totalFee + $sendCost;
+		$oData['orderName'] = $goodsNum > 1 ? $orderName . '等' . $goodsNum . '件商品' : $orderName;
+		if (isset($post['sourceType']) && $post['sourceType'] == 'cart') {
+			if (!empty($goodsIdList)) {
+				foreach ($goodsIdList as $key => $goodsId) {
+					xhCartService::delByIds($userId, $goodsId, $multiPriceIdList[$key]);//删除购物车($userId, $goodsId, $goodsPriceId, $cartId)
+				}
+			}
 		}
-		$typeList = configDict::getConfig('capitalType');
-		$capitalType = $typeList['xhOrder']['id'];
-		$totalFee = $order['actPrice'];
-		$return = xhPayToolService::balancePay($orderId, $totalFee, $capitalType, $couponId);
-		echo Json::encode($return);
+		$userAsset = xhUserAssetService::getByUserId($userId);
+		$level = $userAsset['memberLevel'];
+		if ($level > 0) {
+			$gradeList = xhMerchantExtendService::getGradeList($this->merchantExtend);
+			$discount = $gradeList[$level]['discount'];
+			$discount = strlen($discount) == 1 ? $discount * 10 : $discount;
+			$totalFee = number_format($discount * $totalFee / 100, 2);
+		}
+		$oData['actPrice'] = $totalFee + $sendCost - $couponAmount;
+		xhOrderService::updateById($orderId, $oData);
+		util::successInfo('订单创建成功', 'A0001', ['orderId' => $orderId, 'couponId' => $couponId]);
 	}
-	
+
 	public function actionGetParams()
 	{
 		ini_set('date.timezone', 'Asia/Shanghai');
@@ -152,13 +166,11 @@ class PayController extends BaseController
 		$shopId = isset($post['shopId']) ? $post['shopId'] : 0;
 		//来源 0自建商城 1门店 2微信朋友圈 3淘宝
 		$sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
-		
 		$shopInfo = xhShop::find()->where(['id' => $shopId])->one();
 		if (empty($shopInfo) || $shopInfo->merchantId != $this->merchantId) {
-			util::failInfo('门店无效');
+			util::fail('门店无效');
 		}
 		
-		unset($post['_csrf']);
 		unset($post['payWay']);
 		$post['userId'] = $this->userId;
 		$prePrice = round($post['prePrice'], 2);//四舍五入,保留二位小数
@@ -197,27 +209,27 @@ class PayController extends BaseController
 		$post['payStyle'] = 0;
 		$post['merchantId'] = $this->merchantId;
 		$now = time();
-		$expireTime = $now + 300;//订单5分钟后过期
+		$expireTime = $now + 1800;//订单30分钟后过期
 		$post['createTime'] = date("Y-m-d H:i:s", $now);
 		$post['deadline'] = $expireTime;
 		if (!empty($couponId)) {
 			$time = time();
 			$coupon = CouponService::getById($couponId);
 			if ($coupon['deadline'] <= $time) {
-				util::failInfo('优惠卷已经过期');
+				util::fail('优惠卷已经过期');
 			}
 			if ($coupon['status'] == 1) {
-				util::failInfo('优惠卷已经使用');
+				util::fail('优惠卷已经使用');
 			}
 			if ($coupon['meetAmount'] > $post['prePrice']) {
-				util::failInfo('消费金额不足' . $coupon['meetAmount'] . '元');
+				util::fail('消费金额不足' . $coupon['meetAmount'] . '元');
 			}
 			$post['actPrice'] = stringUtil::calcSub($post['prePrice'], $coupon['amount']);//浮点相减
 			$post['discountAmount'] = $coupon['amount'];
 			$post['discountType'] = 0;
 		}
 		if ($post['actPrice'] <= 0) {
-			util::failInfo('消费金额太低');
+			util::fail('消费金额太低');
 		}
 		if ($this->isWeixin) {
 			$post['modPriceStatus'] = 1;//微信已经提交不能再修改价格
@@ -226,9 +238,9 @@ class PayController extends BaseController
 		$post['id'] = stringUtil::generateOrderNo($this->merchantId, $this->userId);
 		$payment = xhOrderService::add($post);
 		$orderId = $payment['id'];
-		
+
 		if ($payWay == 'balance') {//余额支付
-			util::successInfo('操作成功', 'A0001', ['orderId' => $orderId]);
+			util::success(['orderId' => $orderId]);
 		}
 		$name = '购买商品';
 		$totalFee = $post['actPrice'];
@@ -236,7 +248,7 @@ class PayController extends BaseController
 			$userId = $post['userId'];
 			$user = xhUserService::getById($userId);
 			if ($user['merchantId'] != $this->merchantId) {
-				util::failInfo('非法用户');
+				util::fail('非法用户');
 			}
 			$openId = $user['openId'];
 			$typeList = configDict::getConfig('capitalType');
@@ -270,286 +282,9 @@ class PayController extends BaseController
 			$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $this->merchantExtend);
 			$newParams = json_decode($jsApiParameters, true);
 			$newParams['orderId'] = $orderId;
-			util::successInfo('操作成功', 'A0001', $newParams);
+			util::success($newParams);
 		}
-		util::successInfo('操作成功', 'A0001', ['orderId' => $orderId]);
+		util::success(['orderId' => $orderId]);
 	}
-	
-	public function actionExecAlipay()
-	{
-		header("Content-type: text/html; charset=utf-8");
-		$get = Yii::$app->request->get();
-		$orderId = isset($get['orderId']) ? $get['orderId'] : 0;
-		$couponId = isset($get['couponId']) ? $get['couponId'] : 0;
-		$pay = xhOrderService::getById($orderId);
-		$merchantId = $pay['merchantId'];
 
-		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');
-		//require_once($alipayWap . '/config.php');
-		
-		
-		$totalFee = $pay['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);
-		$this->renderPartial('execAlipay', ['result' => $result]);
-	}
-	
-	public function actionActive()
-	{
-		$get = Yii::$app->request->get();
-		$id = isset($get['id']) ? $get['id'] : 0;
-		$active = xhActiveService::getById($id);
-		if ($active['merchantId'] != $this->merchantId) {
-			util::stop('非法访问。');
-		}
-		$ticketIdList = explode(',', $active['classIdList']);
-		$ticketId = $ticketIdList[0];//目前阶段,创建的活动,只有一种票
-		$ticketClass = xhActiveTicketClassService::getById($ticketId);
-		if (empty($ticketClass) || $ticketClass['merchantId'] != $this->merchantId) {
-			util::stop('非法访问!');
-		}
-		$apply = false;
-		return $this->render('active', ['ticketClass' => $ticketClass, 'apply' => $apply, 'user' => $this->user, 'active' => $active]);
-	}
-	
-	/**
-	 * (必须登录状态)填写收货人信息
-	 */
-	public function actionReceiveInfo()
-	{
-		$get = Yii::$app->request->get();
-		$payId = $get['payId'];
-		if (empty($payId)) {
-			return $this->renderPartial('noGoodsReceiveInfo');
-		}
-		$orderData = xhOrderService::getById($payId, $this->merchantId);
-		if (empty($orderData)) {
-			util::failInfo('订单号未找到');
-		}
-		if ($orderData['userId'] != 0 && $orderData['userId'] != $this->userId) {//当 某用户操作后,就只能该用户访问
-			util::failInfo('不是您的订单');
-		}
-		$orderData['reachTime'] = substr($orderData['reachTime'], 0, 10);
-		$orderData['isPayed'] = 0;
-		$waitForPay = configDict::getConfig('payStatus', 'waitForPay');
-		if ($orderData['payStatus'] != $waitForPay) {
-			$orderData['isPayed'] = 1;
-		}
-		return $this->renderPartial('receiveInfo', ['orderData' => $orderData, 'merchant' => $this->merchant, 'isLogin' => $this->isLogin]);
-		
-	}
-	
-	/**
-	 * (必须登录状态)保存收货人信息成功
-	 */
-	public function actionSaveReceiveInfo()
-	{
-		$payAdd = [];
-		$post = Yii::$app->request->post();
-		//dump($post);die;
-		$payId = $post['payId'];
-		$paymentData = xhOrderService::getById($payId, $this->merchantId);
-		
-		if (empty($paymentData)) {
-			util::failInfo('订单号未找到');
-		}
-		if ($paymentData['userId'] != 0 && $paymentData['userId'] != $this->userId) {//当 快速下单时,字段userId为0(未保存指定用户);用户操作后,就只能该用户访问
-			util::failInfo('不是您的订单');
-		}
-		if ($paymentData['userId'] == 0) {//保存用户id
-			$payAdd['userId'] = $this->userId;
-		}
-		xhOrderService::formatPost($payAdd, $post);
-		unset($payAdd['orderName']);//不更新商品名称
-		unset($payAdd['actPrice']);//不更新价格
-		$re = xhOrderService::updateById($payId, $payAdd);
-		
-		$data['payStatus'] = $paymentData['payStatus'];//支付状态
-		$data['orderId'] = $payId;
-		if ($re['status']) {
-			util::successInfo('保存成功', 'A0001', $data);
-		} else {
-			util::failInfo('保存成功', 'A0003', $data);
-		}
-	}
-	
-	/**
-	 * 支付并填写收花信息、保存收货人信息 -- 成功页
-	 */
-	public function actionReceiveSuccess()
-	{
-		$direction = Yii::$app->request->get('direction');
-		switch ($direction) {
-			case 'paySuccess':
-				return $this->renderPartial('paySuccess');
-			
-			case 'updateSuccess':
-				return $this->renderPartial('updateSuccess');
-		}
-	}
-	
-	/**
-	 * (未登录状态)填写收货人信息
-	 */
-	public function actionNotLoginReceiveInfo()
-	{
-		$get = Yii::$app->request->get();
-		$payId = $get['payId'];
-		$payWay = isset($get['payWay']) ? $get['payWay'] : '';
-		if (empty($payId)) {
-			return $this->renderPartial('noGoodsReceiveInfo');
-		}
-		$orderData = xhOrderService::getById($payId, $this->merchantId);
-		if (!empty($payWay) && ($payWay == 'zfb' || $payWay == 'weixin')) {//微信 或 支付宝跳转的链接
-			if ($orderData['payStatus'] != 1) {
-				util::failInfo('订单号支付失败');
-			}
-		}
-		if (empty($orderData)) {
-			util::failInfo('订单号未找到');
-		}
-		if ($orderData['userId'] != 0 && $orderData['userId'] != $this->userId) {//当 某用户操作后,就只能该用户访问
-			util::failInfo('不是您的订单');
-		}
-		//session校验
-		$orderId = Yii::$app->session->get('orderId_' . $payId);
-		if (empty($orderId)) {
-			util::failInfo('订单号有效期已过,请联系卖家');
-		}
-		if ($orderId != $payId) {
-			util::failInfo('订单号不匹配');
-		}
-		
-		$orderData['reachTime'] = substr($orderData['reachTime'], 0, 10);
-		$orderData['isPayed'] = 0;
-		$waitForPay = configDict::getConfig('payStatus', 'waitForPay');
-		if ($orderData['payStatus'] != $waitForPay) {
-			$orderData['isPayed'] = 1;
-			if ($this->isWeixin) {
-			} else {
-			}
-		}
-		return $this->renderPartial('receiveInfo', ['orderData' => $orderData, 'merchant' => $this->merchant, 'isLogin' => $this->isLogin]);
-		
-	}
-	
-	/**
-	 * (未登录状态)保存收货人信息成功
-	 */
-	public function actionNotLoginSaveReceiveInfo()
-	{
-		$payAdd = [];
-		$post = Yii::$app->request->post();
-		$payId = $post['payId'];
-		$paymentData = xhOrderService::getById($payId, $this->merchantId);
-		
-		if (empty($paymentData)) {
-			util::failInfo('订单号未找到');
-		}
-		if ($paymentData['userId'] != 0 && $paymentData['userId'] != $this->userId) {//当 快速下单时,字段userId为0(未保存指定用户);用户操作后,就只能该用户访问
-			util::failInfo('不是您的订单');
-		}
-		//session校验
-		$orderId = Yii::$app->session->get('orderId_' . $payId);
-		if (empty($orderId)) {
-			util::failInfo('订单号有效期已过,请联系卖家');
-		}
-		if ($orderId != $payId) {
-			util::failInfo('订单号不匹配');
-		}
-		$payAdd['userId'] = 0;
-		
-		xhOrderService::formatPost($payAdd, $post);
-		unset($payAdd['orderName']);//不更新商品名称
-		unset($payAdd['actPrice']);//不更新价格
-		$re = xhOrderService::updateById($payId, $payAdd);
-		if ($re) {
-			util::successInfo('保存成功');
-		} else {
-			util::failInfo('表单数据未变更', 'A0003');
-		}
-	}
-	
-	//取我的优惠卷 shish 2019.8.30
-	public function actionGetMyCoupon()
-	{
-		$get = Yii::$app->request->get();
-		$couponList = CouponService::getAvailableCouponList($get);
-		util::success($couponList);
-	}
-	
 }