|
|
@@ -4,43 +4,33 @@ namespace client\controllers;
|
|
|
|
|
|
use biz\goods\services\CategoryService;
|
|
|
use biz\goods\services\GoodsCategoryService;
|
|
|
+use biz\merchant\services\MerchantService;
|
|
|
+use biz\merchant\services\ShopService;
|
|
|
+use common\components\configDict;
|
|
|
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('支付功能未开通,暂时无法购买哦~');
|
|
|
+ $lat = $post['receiveLat'];//收货人纬度
|
|
|
+ $lng = $post['receiveLong'];//收货人经度
|
|
|
+ $defaultShopId = MerchantService::getDefaultShopId($this->merchant);
|
|
|
+ if (empty($defaultShopId)) {
|
|
|
+ util::fail('没有找到门店');
|
|
|
}
|
|
|
+ $shopInfo = ShopService::getById($defaultShopId);
|
|
|
+
|
|
|
+ $calcDistance = ShopService::calcDistance($lat, $lng, $shopInfo);
|
|
|
+
|
|
|
$couponAmount = 0;
|
|
|
$couponId = isset($post['couponId']) ? $post['couponId'] : 0;//代金劵
|
|
|
if (!empty($couponId)) {
|
|
|
@@ -58,7 +48,7 @@ class OrderController extends BaseController
|
|
|
unset($post['couponId']);
|
|
|
$post['merchantId'] = $this->merchantId;
|
|
|
//店铺id
|
|
|
- $post['shopId'] = $this->merchant['defaultShopId'];
|
|
|
+ $post['shopId'] = $defaultShopId;
|
|
|
$order = xhOrderService::add($post);//创建订单
|
|
|
if ($order == false) {
|
|
|
util::fail('创建订单失败');
|
|
|
@@ -87,12 +77,10 @@ class OrderController extends BaseController
|
|
|
util::fail('订单的商品不存在');
|
|
|
}
|
|
|
$goodPrice = xhGoodsPriceService::getById($val['multiPriceId']);
|
|
|
-
|
|
|
- //$price = $goodPrice['price'];
|
|
|
- $price = xhGoodsSettingService::changePrice($goods, $goodPrice['price']);//统一对商品进行价格等方面设置
|
|
|
+ //统一对商品进行价格等方面设置
|
|
|
+ $price = xhGoodsSettingService::changePrice($goods, $goodPrice['price']);
|
|
|
//多种价格规格 替换 默认(单价格)
|
|
|
$goods['goodsName'] = $goodPrice['title'];
|
|
|
- //$goods['cover'] = $goodPrice['picture'];//后台图片上传功能未开发,暂时使用默认商品图片
|
|
|
$multiPriceId = $val['multiPriceId'];
|
|
|
}
|
|
|
$totalFee += $price * $num;
|
|
|
@@ -116,13 +104,6 @@ class OrderController extends BaseController
|
|
|
$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) {
|
|
|
@@ -133,7 +114,7 @@ class OrderController extends BaseController
|
|
|
}
|
|
|
$oData['actPrice'] = $totalFee + $sendCost - $couponAmount;
|
|
|
xhOrderService::updateById($orderId, $oData);
|
|
|
- util::successInfo('订单创建成功', 'A0001', ['orderId' => $orderId, 'couponId' => $couponId]);
|
|
|
+ util::success(['orderId' => $orderId, 'couponId' => $couponId]);
|
|
|
}
|
|
|
|
|
|
//获取商城下单要用的微信支付参数 shish 2019.21.3
|
|
|
@@ -206,7 +187,7 @@ class OrderController extends BaseController
|
|
|
$updateData['deadline'] = $expireTime;
|
|
|
}
|
|
|
xhOrderService::updateById($orderId, $updateData);//已经请求微信不能修改价格
|
|
|
- util::successInfo('操作成功', 'A0001', $newParams);
|
|
|
+ util::success($newParams);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -338,7 +319,7 @@ class OrderController extends BaseController
|
|
|
$orderId = $payment['id'];
|
|
|
|
|
|
if ($payWay == 'balance') {//余额支付
|
|
|
- util::successInfo('操作成功', 'A0001', ['orderId' => $orderId]);
|
|
|
+ util::success(['orderId' => $orderId]);
|
|
|
}
|
|
|
$name = '购买商品';
|
|
|
$totalFee = $post['actPrice'];
|
|
|
@@ -380,11 +361,11 @@ class OrderController 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]);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//快捷支付使用支付宝付款 shish 2019.12.3
|
|
|
public function actionFastZfbPay()
|
|
|
{
|
|
|
@@ -478,5 +459,5 @@ class OrderController extends BaseController
|
|
|
$result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
|
|
|
$this->renderPartial('execAlipay', ['result' => $result]);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|