Parcourir la source

配送相关字段

shish il y a 6 ans
Parent
commit
b5663f87f8

+ 23 - 42
app/client/controllers/OrderController.php

@@ -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]);
 	}
-
+	
 }

+ 13 - 0
biz/merchant/classes/ShopClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\merchant\classes;
+
+use Yii;
+use biz\base\classes\BaseClass;
+
+class ShopClass extends BaseClass
+{
+
+	public static $baseFile = '\biz\merchant\models\Shop';
+
+}

+ 13 - 0
biz/merchant/models/Shop.php

@@ -0,0 +1,13 @@
+<?php
+namespace biz\merchant\models;
+use biz\base\models\Base;
+
+class Shop extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhShop';
+	}
+
+}

+ 11 - 4
biz/merchant/services/MerchantService.php

@@ -23,15 +23,22 @@ class MerchantService extends BaseService
 		
 		//业务端总共有哪些权限
 		$idList = AuthService::getListId($endId);
-
+		
 		//套餐在业务端有哪些权限
 		$setIdList = SetAuthService::getAuthIdList($setId, $endId);
-
+		
 		//有*号表示有所有的权限
-		$commonIdList = in_array('*',$setIdList) ? $idList : array_intersect($idList, $setIdList);
-
+		$commonIdList = in_array('*', $setIdList) ? $idList : array_intersect($idList, $setIdList);
+		
 		return $commonIdList;
 		
 	}
+
+	//获取默认门店
+	public static function getDefaultShopId($merchant)
+	{
+		$defaultShopId = isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
+		return $defaultShopId;
+	}
 	
 }

+ 40 - 0
biz/merchant/services/ShopService.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace biz\merchant\services;
+
+use biz\base\services\BaseService;
+use common\components\util;
+use Yii;
+
+class ShopService extends BaseService
+{
+
+	public static $baseFile = '\biz\merchant\classes\ShopClass';
+
+	//后端计算订单距离 shish 2019.12.4
+	public static function calcDistance($lat, $lng, $shopInfo)
+	{
+		
+		$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;
+		}
+		
+		
+		$shopLat = $shopInfo['shopLat'];//门店纬度
+		$shopLong = $shopInfo['shopLong'];//门店经度
+		$calcDistance = util::getDistance($shopLat, $shopLong, $lat, $lng);
+		return $calcDistance;
+	}
+
+}

+ 18 - 0
sql.txt

@@ -1,3 +1,21 @@
+2019.12.4 11:44 shish
+ALTER TABLE xhShop CHANGE `businessName` `shopName` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '门店名称';
+ALTER TABLE xhShop CHANGE `branchName` `merchantName` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '商家名称';
+ALTER TABLE xhShop DROP COLUMN `poiId`;
+ALTER TABLE xhMerchantExtend ADD `freight` CHAR(10) NOT NULL DEFAULT '5_2' COMMENT '运费计算方式 5公里内免运费,超过每增加一公里+2' AFTER `alipayAccountName`;
+ALTER TABLE xhMerchantExtend DROP COLUMN `giveCoupon`;
+ALTER TABLE xhMerchantExtend DROP COLUMN `giveCouponPrice`;
+ALTER TABLE xhMerchantExtend DROP COLUMN `couponMeetPrice`;
+ALTER TABLE xhMerchantExtend DROP COLUMN `couponValidity`;
+ALTER TABLE xhMerchantExtend ADD newCouponSwitch TINYINT NOT NULL DEFAULT 1 COMMENT '新人送优惠券 0未开启 1开启' AFTER `freight`;
+ALTER TABLE xhMerchantExtend ADD newCouponAmount DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '新人优惠券金额' AFTER `newCouponSwitch`;
+ALTER TABLE xhMerchantExtend ADD newCouponMiniCost DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '新人优惠券最低消费金额' AFTER `newCouponAmount`;
+ALTER TABLE xhMerchantExtend ADD newCouponValidTime INT NOT NULL DEFAULT 0 COMMENT '新人优惠券有效期,时长为秒,0永不过期' AFTER `newCouponMiniCost`;
+ALTER TABLE xhGoods DROP COLUMN `isCharge`;
+ALTER TABLE xhGoods DROP COLUMN `sendArea`;
+ALTER TABLE xhGoods CHANGE `sendType` needSend TINYINT NOT NULL DEFAULT 0 COMMENT '是否要配送 0免配送 1需要配送';
+ALTER TABLE xhOrder CHANGE `needSend` `sendType` TINYINT NOT NULL DEFAULT 0 COMMENT '配送方式 0免配送 1自己送 2别人送';
+
 2019.12.4 shish
 !!执行下面的sql,全部的会员折扣要纠正
 UPDATE xhUserAsset SET `discount`=1;