Ver Fonte

下单流程

shish há 5 anos atrás
pai
commit
d84e7be04b

+ 401 - 178
app/ghs/controllers/OrderController.php

@@ -2,15 +2,17 @@
 
 namespace ghs\controllers;
 
+use biz\merchant\services\ExpressService;
 use biz\merchant\services\MerchantAssetService;
 use biz\merchant\services\MerchantExtendService;
 use biz\merchant\services\MerchantService;
 use bizGhs\merchant\services\ShopService;
 use biz\order\classes\OrderSendClass;
-use biz\order\services\OrderService;
+use bizGhs\order\services\OrderService;
 use biz\saas\services\RegionService;
 use biz\user\services\UserService;
 use common\components\configDict;
+use common\components\httpUtil;
 use common\services\xhPayToolService;
 use Yii;
 use common\components\util;
@@ -18,182 +20,403 @@ use common\components\stringUtil;
 
 class OrderController extends BaseController
 {
-	
-	public function actionList()
-	{
-		$get = Yii::$app->request->get();
-		$search = isset($get['search']) ? $get['search'] : '';
-		$where = [];
-		$where['merchantId'] = $this->merchantId;
-		if (isset($get['status']) && $get['status'] != -1) {
-			$where['status'] = $get['status'];
-		}
-		if (!empty($search)) {
-			if (stringUtil::isMobile($search)) {
-				$where['receiveMobile'] = $search;
-			} else {
-				$where['id'] = $search;
-			}
-		}
-		$list = OrderService::getOrderList($where);
-		$list['asset'] = MerchantAssetService::getByMerchantId($this->merchantId);
-		util::success($list);
-	}
-	
-	//订单详情 shish 2019.12.16
-	public function actionDetail()
-	{
-		$id = Yii::$app->request->get('id');
-		$detail = OrderService::getOrderById($id);
-		util::success($detail);
-	}
-	
-	//订单归类 shish 2019.12.17
-	public function actionClassify()
-	{
-		$post = Yii::$app->request->post();
-		$id = isset($post['id']) ? $post['id'] : 0;
-		$order = OrderService::getById($id);
-		OrderService::valid($order, $this->merchantId);
-		$categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
-		$usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
-		OrderService::classify($id, $categoryId, $usageId);
-		util::complete();
-	}
-	
-	//更新配送单 shish 2019.12.17
-	public function actionUpdateSheet()
-	{
-		$post = Yii::$app->request->post();
-		$id = isset($post['id']) ? $post['id'] : 0;
-		unset($post['id']);
-		$order = OrderService::getById($id);
-		OrderService::valid($order, $this->merchantId);
-		OrderService::updateSheet($order, $post);
-		util::complete('提交成功');
-	}
-	
-	//商家收款与发货 shish 2019.12.18
-	public function actionGathering()
-	{
-		$post = Yii::$app->request->post();
-		$price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
-		$payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
-		$userId = isset($post['userId']) ? $post['userId'] : 0;
-		$userInfo = UserService::getById($userId);
-		if (empty($userInfo) || $userInfo['merchantId'] != $this->merchantId) {
-			util::fail('您选择的客户无效');
-		}
-		if ($price <= 0) {
-			util::fail('请输入金额');
-		}
-		$post['prePrice'] = $price;
-		$post['actPrice'] = $price;
-		$post['payWay'] = $payWay;
-		$post['sourceType'] = 1;
-		$post['userId'] = $userId;
-		$post['goodsNum'] = 1;
-		$post['orderName'] = '商品';
-		$shopId = MerchantService::getDefaultShopId($this->merchant);
-		$post['shopId'] = $shopId;
-		$order = OrderService::addOrder($post);
-		$id = $order['id'];
-		$orderSn = $order['orderSn'];
-		
-		//流水类型列表
-		$capitalTypeList = configDict::getConfig('capitalType');
-		$capitalType = $capitalTypeList['xhOrder']['id'];
-		$callbackParams = [];
-		switch ($payWay) {
-			case 0:
-				xhPayToolService::weixinPay($callbackParams, $orderSn, $price, $capitalType, 0);
-				break;
-			case 1:
-				xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
-				break;
-			case 2:
-				xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
-				break;
-			default:
-				util::fail('无效支付方式');
-		}
-		util::success($order);
-	}
-	
-	//免发货管理 shish 2020.1.6
-	public function actionWithoutSend()
-	{
-		$id = Yii::$app->request->get('id');
-		$order = OrderService::getById($id);
-		OrderService::valid($order, $this->merchantId);
-		//配送流程变更
-		$currentFlow = OrderSendClass::withoutSend($order);
-		util::success(['currentFlow' => $currentFlow]);
-	}
-	
-	//修改价格 shish 2020.1.6
-	public function actionUpdatePrice()
-	{
-		$id = Yii::$app->request->get('id');
-		$price = Yii::$app->request->get('price', 1);
-		$order = OrderService::getById($id);
-		OrderService::valid($order, $this->merchantId);
-		if (isset($order['modPrice']) && $order['modPrice'] == 0) {
-			util::fail('已发起支付,不能修改价格');
-		}
-		OrderService::updateById($id, ['actPrice' => $price]);
-		util::complete('修改成功');
-	}
-	
-	//下单要用到的相关信息 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, 'merchant' => $this->merchant];
-		util::success($out);
-	}
-	
-	//配送单 shish 2020.2.29
-	public function actionGetDeliverDetail()
-	{
-		$id = Yii::$app->request->get('id', 0);
-		$order = OrderService::getById($id);
-		OrderService::valid($order, $this->merchantId);
-		$reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
-		$reachPeriodId = $order['reachPeriod'];
-		$reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
-		$reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
-		$shopId = $order['shopId'];
-		$telephone = '';
-		if (!empty($shopId)) {
-			$shop = ShopService::getById($shopId);
-		}
-		$telephone = isset($shop['telephone']) ? $shop['telephone'] : '';
-		$bookName = isset($order['bookName']) ? $order['bookName'] : '';
-		$bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
-		if (isset($order['anonymity']) && $order['anonymity'] == 1) {
-			$bookName = '--';
-			$bookMobile = '--';
-		}
-		$data = [
-			'reachDate' => $reachDate . ' ' . $reachPeriod,
-			'orderSn' => $order['orderSn'],
-			'receiveUserName' => $order['receiveUserName'],
-			'receiveMobile' => $order['receiveMobile'],
-			'receiveFullAddress' => $order['receiveAddress'] . $order['receiveFloor'] . "(" . $order['receiveFullAddress'] . ")",
-			'cardInfo' => $order['cardInfo'],
-			'bookMobile' => $bookMobile,
-			'bookName' => $bookName,
-			'remark' => $order['remark'],
-			'sendNum' => $order['sendNum'],
-			'telephone' => 13600903070,
-			'printTime' => '',
-			'img' => '',
-		];
-		util::success($data);
-	}
+
+    public $withoutLogin = ['order-relate', 'fast-pay'];
+
+    //商城下单操作 shish 2021.1.14
+    public function actionCreateOrder()
+    {
+        $post = Yii::$app->request->post();
+        $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
+        $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
+        $needSend = $post['needSend'] ?? 1;
+//        if (empty($goodsId)) {
+//            util::fail('请选择商品');
+//        }
+//        $goodsInfo = GoodsService::getGoodsInfo($goodsId);
+//        if (empty($goodsInfo)) {
+//            util::fail('没有找到商品');
+//        }
+//        if (isset($goodsInfo['stock']) == false || $goodsInfo['stock'] == 0) {
+//            util::fail('已经卖完了');
+//        }
+
+        //运费计算方式
+        $freightType = $goodsInfo['freightType'] ?? 0;
+
+        //$post['adminId'] = $this->adminId;
+        $post['adminId'] = 0;
+        $user = $this->admin;
+        $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
+        $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
+        $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
+        $post['bookMobile'] = $bookMobile;
+
+        $post['payWay'] = $this->isWx == true ? 0 : 1;
+        $defaultShopId = MerchantService::getDefaultShopId($this->ghs);
+        if (empty($defaultShopId)) {
+            util::fail('没有找到门店');
+        }
+        //计算运费
+        $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
+        $sendCost = 0;
+        //按距离计算运费并且客户要求送的
+        if ($freightType == 0 && $needSend == 1) {
+            $lat = $post['latitude'];//收货人纬度
+            $lng = $post['longitude'];//收货人经度
+            $respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->ghsExtend);
+            $sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
+        }
+        $post['sendCost'] = $sendCost;
+        $post['merchantId'] = $this->ghsId;
+        $post['shopId'] = $defaultShopId;
+
+        //计算总金额
+        //$unitPrice = $goodsInfo['price'];
+        $unitPrice = 1;
+
+        $goodsPrice = $unitPrice * $goodsNum;
+        $prePrice = stringUtil::calcAdd($sendCost, $goodsPrice);
+        //非门店订单
+        $store = 0;
+        $post['store'] = $store;
+        //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
+        $sourceType = $this->isWx ? 0 : 1;
+        if (httpUtil::isMiniProgram()) {
+            $sourceType = 2;
+        }
+        $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
+        $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
+        $actPrice = $discountData['price'];
+        $post['discountType'] = $discountData['discountType'];
+        $post['discountAmount'] = $discountData['discountAmount'];
+
+        $now = time();
+        $expireTime = $now + 1800;//订单30分钟后过期
+        $post['deadline'] = $expireTime;
+        $post['fromType'] = 1;//商城
+        $post['prePrice'] = $prePrice;
+        $post['actPrice'] = $actPrice;
+        $order = OrderService::addOrder($post);
+        $orderId = $order['id'];
+        $orderSn = $order['orderSn'];
+        $data = [
+            'orderId' => $orderId,
+            'goodsId' => $goodsId,
+            'userId' => $this->adminId,
+            'merchantId' => $this->ghsId,
+            'title' => '苏醒',
+            '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' => $actPrice, 'couponId' => $couponId]);
+    }
+
+    //下单要用到的相关信息 shish 2019.12.6
+    public function actionOrderRelate()
+    {
+        $regionTree = RegionService::tree();
+        $shop = ShopService::getDefaultShop($this->ghs);
+        $freight = MerchantExtendService::getFreight($this->ghsExtend);
+        $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
+        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->ghs];
+        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;
+
+        //验证优惠券是否还有效
+        if (!empty($couponId)) {
+            CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
+        }
+
+        $order = OrderService::getByOrderSn($orderSn);
+        $userId = $this->adminId;
+        $user = UserService::getUserInfo($userId, false);
+        //验证支付密码是否正确
+        UserService::validPayPassword($payPassword, $user);
+        //支付前验证订单有效性
+        OrderService::checkBeforePay($order, $this->adminId);
+        $typeList = configDict::getConfig('capitalType');
+        $capitalType = $typeList['xhOrder']['id'];
+        $totalFee = $order['prePrice'];
+        $sourceType = 0;
+        $discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
+        $actPrice = $discountData['price'];
+        $callbackParams = [];
+        $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
+        $balance = isset($respond['balance']) ? $respond['balance'] : 0;
+        util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
+    }
+
+    //获取商城下单要用的微信支付和小程序支付参数 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'];
+
+        //验证优惠券是否还有效
+        if (!empty($couponId)) {
+            CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
+        }
+
+        //支付前验证订单有效性
+        OrderService::checkBeforePay($order, $this->adminId);
+
+        $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
+        $totalFee = $order['actPrice'];
+
+        //小程序使用miniOpenId
+        if (httpUtil::isMiniProgram()) {
+            $openId = $this->admin['miniOpenId'];
+        } else {
+            $openId = $this->admin['openId'];
+        }
+        $typeList = configDict::getConfig('capitalType');
+        $capitalType = $typeList['xhOrder']['id'];
+        //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
+        $wxPayType = 0;
+        if (httpUtil::isMiniProgram()) {
+            $wxPayType = 1;
+        }
+        $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
+        //订单30分钟后过期
+        $now = time();
+        $expireTime = $now + 1800;
+
+        $wx = Yii::getAlias("@vendor/weixin");
+        require_once($wx . '/lib/WxPay.Api.php');
+        require_once($wx . '/example/WxPay.JsApiPay.php');
+        $input = new \WxPayUnifiedOrder();
+        $input->SetBody($name);
+        $input->SetOut_trade_no($orderSn);
+        $input->SetTotal_fee($totalFee * 100);
+        $input->SetTime_start(date("YmdHis", $now));
+        $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
+        $input->SetTime_expire(date("YmdHis", $expireTime));
+        $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
+        $input->SetTrade_type("JSAPI");
+
+        //花卉宝代为申请的微信支付
+        $merchantExtend = $this->ghsExtend;
+        if ($merchantExtend['wxPayApply'] == 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->ghs);
+        //验证门店是否有效
+        $shopInfo = ShopService::getById($shopId);
+        ShopService::valid($shopInfo, $this->ghsId);
+        $post['shopId'] = $shopId;
+        //默认门店订单
+        $store = isset($post['store']) ? $post['store'] : 1;
+        $post['store'] = $store;
+        //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
+        $sourceType = $this->isWx ? 0 : 1;
+        if (httpUtil::isMiniProgram()) {
+            $sourceType = 2;
+        }
+        $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
+        //兼容旧系统sourceType=3表示朋友圈来源
+        $fromType = $sourceType == 3 ? 2 : 0;
+        $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
+        $post['userId'] = $this->adminId;
+        $user = $this->admin;
+        $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
+        $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
+        $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
+        $post['bookMobile'] = $bookMobile;
+        $prePrice = round($post['prePrice'], 2);
+        $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
+        $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
+        $actPrice = $discountData['price'];
+        $post['discountType'] = $discountData['discountType'];
+        $post['discountAmount'] = $discountData['discountAmount'];
+        $post['actPrice'] = $actPrice;
+        $post['payStyle'] = 0;
+        $post['merchantId'] = $this->ghsId;
+        $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;
+        $post['goodsNum'] = 1;
+        $post['fromType'] = $fromType;
+        $order = OrderService::addOrder($post);
+        $orderId = $order['id'];
+        $orderSn = $order['orderSn'];
+        $merchantId = $this->ghsId;
+        if ($payWay == 0) {
+            $orderId = $order['id'];
+            $name = '购买商品';
+            $totalFee = $actPrice;
+            $user = UserService::getById($this->adminId);
+            $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'];
+            //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
+            $wxPayType = 0;
+            if (httpUtil::isMiniProgram()) {
+                $wxPayType = 1;
+            }
+            $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
+            $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);
+            //设置订单有效期5分钟
+            $input->SetTime_expire(date("YmdHis", $expireTime));
+            $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
+            $input->SetTrade_type("JSAPI");
+
+            //花卉宝代为申请的微信支付
+            $merchantExtend = $this->ghsExtend;
+            if ($merchantExtend['wxPayApply'] == 1) {
+                $input->SetSub_openid($openId);
+            } else {
+                $input->SetOpenid($openId);
+            }
+            //小程序使用miniAppId
+            if (httpUtil::isMiniProgram()) {
+                $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+            }
+            Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
+            $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) {
+            $extend = MerchantExtendService::getByMerchantId($merchantId);
+            if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
+                util::fail('支付宝付款即将开通...');
+            }
+            $config = [
+                //应用ID,您的APPID。
+                'app_id' => $extend['alipayPId'],
+                //商户私钥,您的原始格式RSA私钥
+                'merchant_private_key' => $extend['alipayKey'],
+                //异步通知地址
+                'notify_url' => Yii::$app->params['mallHost'] . "/notice/alipay-callback",
+                //同步跳转
+                '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' => $extend['alipayPublicKey'],
+            ];
+
+            Yii::info(json_encode($config) . ' aplipay config');
+
+            $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 = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
+            $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['mallDomain'] . "/#/pages/callback/success?account={$merchantId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
+            //异步通知
+            $notifyUrl = Yii::$app->params['mallHost'] . "/notice/alipay-callback";
+            $payResponse = new \AlipayTradeService($config);
+            $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
+            //直接将支付宝的html返回给前端
+            echo $result;
+        } elseif ($payWay == 2) {
+            //余额支付,验证支付密码是否正确
+            $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
+            $user = UserService::getUserInfo($this->adminId, false);
+            UserService::validPayPassword($payPassword, $user);
+            $typeList = configDict::getConfig('capitalType');
+            $capitalType = $typeList['xhOrder']['id'];
+            $callbackParams = [];
+            $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
+            $balance = isset($respond['balance']) ? $respond['balance'] : 0;
+            util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
+        } else {
+            util::fail('无效的支付方式');
+        }
+    }
 
 }

+ 209 - 0
biz-ghs/order/classes/OrderClass.php

@@ -0,0 +1,209 @@
+<?php
+
+namespace bizGhs\order\classes;
+
+use common\components\stringUtil;
+use Yii;
+use bizGhs\base\classes\BaseClass;
+
+class OrderClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\order\models\Order';
+
+
+    //已退款
+    const ORDER_STATUS_REFUND = 6;
+    //完成
+    const ORDER_STATUS_COMPLETE = 5;
+    //已取消
+    const ORDER_STATUS_CANCEL = 4;
+    //待通知
+    const ORDER_STATUS_UN_NOTICE = 3;
+    //配送中
+    const ORDER_STATUS_SENDING = 2;
+    //待配送
+    const ORDER_STATUS_UN_SEND = 1;
+    //待付款
+    const ORDER_STATUS_UN_PAY = 0;
+    //订单总流程数
+    const ORDER_TOTAL_FLOW = 4;
+
+    //未确认配送方式
+    const SEND_TYPE_UNKNOWN = 0;
+    //自取
+    const SEND_TYPE_NO = 1;
+    //自己送
+    const SEND_TYPE_MYSELF = 2;
+    //代送
+    const SEND_TYPE_OTHER = 3;
+
+    //送达时间段
+    public static $reachPeriod = [0 => '上午', 1 => '下午', 2 => '晚上'];
+
+    //优惠金额
+    public static $randDiscount = [
+        50 => [1, 3],
+        100 => [5, 9],
+        300 => [10, 15],
+        500 => [16, 18],
+        1000 => [18, 30],
+        20000 => [90, 100],
+    ];
+
+    //添加订单 shish 2019.12.5
+    public static function addOrder($data)
+    {
+        $date = date("Y-m-d H:i:s");
+        $merchantId = $data['merchantId'];
+        $data['orderSn'] = stringUtil::generateOrderNo($merchantId, $data['adminId']);
+        $data['payStatus'] = 0;
+        $data['createTime'] = $date;
+        $data['addTime'] = time();
+
+        $month = date("Ym");
+        $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
+        //将花店每月的总订单数作为编号
+        $data['sendNum'] = $riseNum;
+        $data['totalFlow'] = OrderClass::ORDER_TOTAL_FLOW;
+        $return = self::add($data);
+
+        //全部订单+1,待付款订单+1
+        $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
+        $merchantAsset->unPayOrder += 1;
+        $merchantAsset->totalOrder += 1;
+        $merchantAsset->save();
+
+        return $return;
+    }
+
+    public static function getByOrderSn($orderSn)
+    {
+        return self::getByCondition(['orderSn' => $orderSn]);
+    }
+
+    //评价 shish 2019.12.16
+    public static function comment($data)
+    {
+        $id = $data['id'];
+        unset($data['id']);
+        return self::updateById($id, $data);
+    }
+
+    //订单
+    public static function getOrderById($id)
+    {
+        $order = self::getById($id);
+        if (empty($order)) {
+            return [];
+        }
+        $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
+        return $order;
+    }
+
+    //根据订单查询 shish 2020.1.4
+    public static function getOrderBySn($orderSn)
+    {
+        $order = self::getByCondition(['orderSn' => $orderSn]);
+        if (empty($order)) {
+            return [];
+        }
+        $id = $order['id'];
+        $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
+        return $order;
+    }
+
+    //返回随机优惠金额 shish 2019.9.12
+    public static function getRandDiscount($amount)
+    {
+        if ($amount <= 0) {
+            return 0;
+        }
+        $randDiscount = self::$randDiscount;
+        krsort($randDiscount);
+        $rand = 0;
+        foreach ($randDiscount as $currentAmount => $val) {
+            if ($amount >= $currentAmount) {
+                $rand = rand($val[0], $val[1]);
+                break;
+            }
+        }
+        return $rand / 10;
+    }
+
+    //订单完成 shish 2020.3.12
+    public static function complete($order, $currentFlow)
+    {
+        $id = $order['id'];
+        self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => $currentFlow]);
+    }
+
+    //转化出送到时间 shish 2020.3.15
+    public static function getReachTime($order)
+    {
+        $reachTime = '';
+        if (isset($order['reachDate']) && !empty($order['reachDate'])) {
+            $prev = date("n-j", strtotime($order['reachDate']));
+            $periodData = self::$reachPeriod;
+            $periodKey = $order['reachPeriod'];
+            $period = isset($periodData[$periodKey]) ? $periodData[$periodKey] : '上午';
+            $reachTime = $prev . ' ' . $period;
+        }
+        return $reachTime;
+    }
+
+    //支付成功获取unionId shish 2020.5.12
+    public static function payToUpdateUnionId($merchant, $merchantExtend, $orderSn, $user)
+    {
+        $mcId = $merchantExtend['wxPayMerchantId'];
+        $miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
+        $unionId = isset($user['unionId']) ? $user['unionId'] : '';
+        $userId = $user['id'];
+        if (empty($unionId)) {
+            $unionId = miniUtil::getPaidUnionId($merchant, $miniOpenId, $mcId, (string)$orderSn, 0);
+            if (!empty($unionId)) {
+                $findUser = UserClass::getByUnionId($unionId);
+                if (empty($findUser)) {
+                    UserClass::updateByCondition(['id' => $userId], ['unionId' => $unionId]);
+                } else {
+                    UserClass::mergeUser($findUser, $user);
+                }
+            }
+        }
+    }
+
+    //订单到期未付款的订单置成取消状态 shish 2020.5.25
+    public static function setExpire($order)
+    {
+        $now = time();
+        if (!empty($order['deadline']) && $now > $order['deadline']) {
+            if ($order['status'] == 0) {
+                $id = $order['id'];
+                OrderClass::updateById($id, ['status' => 4]);
+            }
+        }
+    }
+
+    //支付成功需要处理的流程 shish 2020.5.25
+    public static function payAfter($order, $updateData)
+    {
+        $orderId = $order['id'];
+        $now = time();
+        self::updateById($orderId, $updateData);
+        //发货流程的完成下单
+        OrderSendClass::placeOrder(['orderId' => $orderId, 'payTime' => $now]);
+        $merchantId = $order['merchantId'];
+        $asset = MerchantAssetClass::getByMerchantId($merchantId);
+        //增加订单数
+        StatOrderClass::addOrder($merchantId, $asset);
+        //如果门店和朋友圈订单并且没有填写收花人的直接将订单置为自取并且是完成状态
+        if (isset($order['fromType']) && in_array($order['fromType'], [0, 2])) {
+            if (isset($order['receiveMobile']) && isset($order['receiveAddress'])) {
+                if (empty($order['receiveMobile']) && empty($order['receiveAddress'])) {
+                    OrderSendClass::withoutSend($order);
+                }
+            }
+        }
+    }
+
+}

+ 13 - 0
biz-ghs/order/classes/OrderExpressClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace bizGhs\order\classes;
+
+use Yii;
+use bizGhs\base\classes\BaseClass;
+
+class OrderExpressClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\order\models\OrderExpress';
+
+}

+ 13 - 0
biz-ghs/order/models/Order.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizGhs\order\models;
+use bizGhs\base\models\Base;
+
+class Order extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhGhsOrder';
+	}
+
+}

+ 13 - 0
biz-ghs/order/models/OrderExpress.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizGhs\order\models;
+use bizGhs\base\models\Base;
+
+class OrderExpress extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhGhsOrderExpress';
+	}
+
+}

+ 13 - 0
biz-ghs/order/services/OrderExpressService.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace bizGhs\order\services;
+
+use bizGhs\base\services\BaseService;
+use Yii;
+
+class OrderExpressService extends BaseService
+{
+
+    public static $baseFile = '\bizGhs\order\classes\OrderExpressClass';
+
+}

+ 222 - 0
biz-ghs/order/services/OrderService.php

@@ -0,0 +1,222 @@
+<?php
+
+namespace bizGhs\order\services;
+
+use bizGhs\base\services\BaseService;
+use bizGhs\order\classes\OrderClass;
+use Yii;
+
+class OrderService extends BaseService
+{
+
+    public static $baseFile = '\bizGhs\order\classes\OrderClass';
+
+
+    //添加订单
+    public static function addOrder($data)
+    {
+        return OrderClass::addOrder($data);
+    }
+
+    //获取订单信息 shish 2019.11.28
+    public static function getOrderList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        if (isset($data['list']) == false || empty($data['list'])) {
+            return $data;
+        }
+
+        $orderIds = array_column($data['list'], 'id');
+
+        //获取订单的商品信息
+        $goodsList = OrderGoodsService::getGoodsListByOrderIds($orderIds);
+
+        //获取订花人的用户信息
+        $orderUserIds = array_column($data['list'], 'userId');
+        $orderUserIds = array_unique($orderUserIds);
+        $userInfoList = UserService::getUserByIds($orderUserIds);
+
+        $merchantIdList = array_column($data['list'], 'merchantId');
+        $merchantIdList = array_filter(array_unique($merchantIdList));
+        $merchantList = MerchantService::getByIds($merchantIdList, null, 'id');
+
+        $periodData = [0 => '上午', 1 => '下午', 2 => '晚上'];
+        foreach ($data['list'] as $key => $val) {
+            $id = $val['id'];
+            $userId = $val['userId'];
+            $data['list'][$key]['goodsInfoList'] = isset($goodsList[$id]) ? $goodsList[$id] : [];
+            $data['list'][$key]['bookAvatar'] = isset($userInfoList[$userId]['smallAvatarUrl']) ? $userInfoList[$userId]['smallAvatarUrl'] : '';
+            $merchantId = $val['merchantId'];
+            $data['list'][$key]['merchantName'] = isset($merchantList[$merchantId]['merchantName']) ? $merchantList[$merchantId]['merchantName'] : '';
+            $data['list'][$key]['reachTime'] = OrderClass::getReachTime($val);
+            $requireReachTime = '';
+            if ($val['reachDate'] != '0000-00-00') {
+                $reachPeriodId = $val['reachPeriod'];
+                $reachPeriod = isset($periodData[$reachPeriodId]) ? $periodData[$reachPeriodId] : '上午';
+                $requireReachTime = date("m-d", strtotime($val['reachDate'])) . ' ' . $reachPeriod;
+            }
+            $data['list'][$key]['requireReachTime'] = $requireReachTime;
+        }
+        return $data;
+    }
+
+    //取客户最近若干条订单 shish 2019.11.30
+    public static function getUserOrder($userId, $limit = 10, $order = null, $with = null)
+    {
+        $where = ['userId' => $userId, 'payStatus' => 1];
+        return self::getLimitList('*', $where, $limit, $order, $with);
+    }
+
+    //支付前验证订单 shish 2019.12.6
+    public static function checkBeforePay($order, $userId)
+    {
+        $now = time();
+        OrderClass::setExpire($order);
+        if (empty($order)) {
+            util::fail('订单无效');
+        }
+        if (isset($order['userId']) && $order['userId'] != $userId) {
+            util::fail('非法访问');
+        }
+        if ($order['status'] != 0) {
+            util::fail('订单不是待付款状态');
+        }
+        if (!empty($order['deadline']) && $now > $order['deadline']) {
+            util::fail('订单已过期');
+        }
+        if (ceil($order['actPrice']) <= 0) {
+            util::fail('订单金额有问题');
+        }
+        if ($order['payStatus'] == 1) {
+            util::fail('您已经付过了');
+        }
+    }
+
+    //商家验证是否有效 shish 2019.12.15
+    public static function valid($order, $merchantId)
+    {
+        OrderClass::setExpire($order);
+        if (empty($order)) {
+            util::fail('订单无效');
+        }
+        if ($order['merchantId'] != $merchantId) {
+            util::fail('不是您的订单');
+        }
+    }
+
+    //根据编号查询 shish 2019.12.14
+    public static function getByOrderSn($orderSn)
+    {
+        return OrderClass::getByOrderSn($orderSn);
+    }
+
+    //点评 shish 2019.12.16
+    public static function comment($data)
+    {
+        return OrderClass::comment($data);
+    }
+
+    //订单归类
+    public static function classify($id, $categoryId, $usageId)
+    {
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            $order = OrderClass::getById($id, true);
+            if ($order->payStatus != 1) {
+                util::fail('订单还未付款');
+            }
+            if ($order->classify == 1) {
+                util::fail('已经归类过了');
+            }
+            $order->categoryId = $categoryId;
+            $order->usageId = $usageId;
+            $order->classify = 1;
+            $order->save();
+
+            //设置流水的分类和用途并分配资金
+            $setData = [
+                'merchantId' => $order->merchantId,
+                'capitalId' => $order->capitalId,
+                'time' => $order->payTime,
+                'usageId' => $order->usageId,
+                'categoryId' => $order->categoryId,
+                'amount' => $order->actPrice,
+                'payWay' => $order->payWay,
+            ];
+            MerchantCapitalService::orderClassify($setData);
+
+            $transaction->commit();
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            util::fail('没有归类成功');
+        }
+    }
+
+    //更新配送单 shish 2019.12.17
+    public static function updateSheet($order, $data)
+    {
+        $id = $order['id'];
+        if ($order['status'] != OrderClass::ORDER_STATUS_UN_SEND) {
+            util::fail('订单当前不是待配送状态');
+        }
+        $data['deliver'] = 1;
+        OrderClass::updateById($id, $data);
+    }
+
+    //订单详情 shish 2020.1.2
+    public static function getOrderById($id)
+    {
+        return OrderClass::getOrderById($id);
+    }
+
+    //查看订单详情 shish 2020.1.4
+    public static function getOrderBySn($orderSn)
+    {
+        return OrderClass::getOrderBySn($orderSn);
+    }
+
+    //计算优惠 shish 2020.3.9
+    public static function getDiscountPrice($params)
+    {
+        $couponId = isset($params['couponId']) ? $params['couponId'] : 0;
+        $userId = isset($params['userId']) ? $params['userId'] : 0;
+        $price = isset($params['price']) ? $params['price'] : 0;
+        $sourceType = isset($params['sourceType']) ? $params['sourceType'] : 0;
+        $discountAmount = 0;
+        $discountType = 0;
+        $discountPrice = $price;
+        //使用优惠券
+        if (!empty($couponId)) {
+            $discountAmount = CouponService::checkBeforeUse($couponId, $price, $userId);
+            $discountPrice = stringUtil::calcSub($price, $discountAmount);
+            $discountType = 1;
+        } else {
+            //使用会员
+//            $asset = UserAssetClass::getByUserId($userId);
+//            if (isset($asset['member']) && $asset['member'] > 0) {
+//                $currentDiscount = $asset['discount'];
+//                $currentPrice = $price * $currentDiscount;
+//                $newPrice = substr(sprintf("%.3f", $currentPrice), 0, -1);
+//                $discountType = 2;
+//                $discountAmount = stringUtil::calcSub($price, $newPrice);
+//                $discountPrice = $newPrice;
+//            }
+        }
+        //如果没有优惠券和会员优惠,并且是朋友圈收款,则进行随机优惠 shish 2019.9.12
+        if ($discountPrice == $price && $sourceType == 3) {
+            $discountAmount = OrderClass::getRandDiscount($price);
+            //开发和测试环境直接随机优惠
+            $env = getenv('YII_ENV');
+            if ($env == 'local' || $env == 'test') {
+                $discountAmount = 0.01;
+            }
+            $discountPrice = stringUtil::calcSub($price, $discountAmount);
+            $discountType = 3;
+        }
+        $discountType = $discountAmount <= 0 ? 0 : $discountType;
+        $discountPrice = $discountPrice <= 0 ? 0.01 : $discountPrice;
+        return ['price' => $discountPrice, 'discountType' => $discountType, 'discountAmount' => $discountAmount];
+    }
+
+}

+ 64 - 1
sql.sql

@@ -452,4 +452,67 @@ ADD COLUMN `stockWarning`  decimal(10,2) NOT NULL DEFAULT 0 COMMENT '库存预
 ========
 == shish 2021-1-13 删掉二个表
 DROP TABLE IF EXISTS `xhGhsOrder`;
-DROP TABLE IF EXISTS `xhGhsOrderItem`;
+DROP TABLE IF EXISTS `xhGhsOrderItem`;
+drop table if exists `xhGhsSellOrder`;
+drop table if exists `xhGhsSellOrderItem`;
+CREATE TABLE `xhGhsOrder` (
+  `id` int(11) NOT NULL AUTO_INCREMENT primary key COMMENT '自增id',
+  `orderSn` char(40) NOT NULL DEFAULT '' COMMENT '订单编号',
+  `goodsNum` tinyint(4) NOT NULL DEFAULT '0' COMMENT '商品数量',
+  `payWay` tinyint(4) NOT NULL DEFAULT '0' COMMENT '支付方式 0微信 1支付宝 2余额',
+  `wxPayType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0 H5支付 1 小程序支付',
+  `payCode` varchar(1000) NOT NULL DEFAULT '' COMMENT '支付返回号',
+  `fromType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '来源:0门店 1商城 2朋友圈',
+  `store` tinyint(4) NOT NULL DEFAULT '0' COMMENT '门店订单 0不是 1是',
+  `capitalId` int(11) NOT NULL DEFAULT '0' COMMENT '流水id',
+  `prePrice` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '应付款,原价,未修改价格,打折前',
+  `actPrice` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '实际付款,实价,修改后价格,打折后',
+  `adminId` int(11) NOT NULL DEFAULT '0' COMMENT '用户id',
+  `ghsId` int(11) NOT NULL DEFAULT '0' COMMENT '商家id',
+  `shopId` int(11) NOT NULL DEFAULT '0' COMMENT '门店id',
+  `sendType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0未确认配送方式 1免配送 2自己送 3别人送;快递送',
+  `sendSide` tinyint(4) NOT NULL DEFAULT '0' COMMENT '配送方 0没有 1达达',
+  `sendStatus` tinyint(4) NOT NULL DEFAULT '0' COMMENT '配送状态:0未发货,待接单 1已发货,已接单 2已送达',
+  `refund` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1已退款 0正常订单',
+  `payStatus` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0待付款 1已付款',
+  `printStatus` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0未打印 1已打印',
+  `remark` varchar(1000) NOT NULL DEFAULT '' COMMENT '备注',
+  `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '订单状态 0待付款 1待配送 2配送中 3待通知 4已取消 5已完成',
+  `deadline` int(11) NOT NULL DEFAULT '0' COMMENT '订单有效期',
+  `payTime` int(11) NOT NULL DEFAULT '0' COMMENT '付款时间',
+  addTime int not null default 0 comment '添加时间',
+  `updateTime` int not null default 0 comment '修改时间'
+) COMMENT='供货商订单';
+create table xhGhsOrderItem(
+`id` int(11) unsigned NOT NULL AUTO_INCREMENT primary key COMMENT 'id',
+`orderId` int(11) NOT NULL DEFAULT '0' COMMENT '订单id',
+`adminId` int(11) NOT NULL DEFAULT '0' COMMENT '用户id',
+`ghsId` int(11) NOT NULL DEFAULT '0' COMMENT '商家id',
+itemId int not null default 0 comment '商家花材id',
+`unitPrice` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '每扎价格',
+unitNum int not null default 0 comment '每扎多少支',
+`num` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '多少扎'
+)comment='供货商订单商品';
+CREATE TABLE `xhGhsOrderExpress` (
+  `id` INT(11) NOT NULL AUTO_INCREMENT,
+  `orderId` INT(11) NOT NULL DEFAULT '0' COMMENT '订单id',
+  `ghsId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家id',
+  `sideId` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '配送方id',
+  `distance` DECIMAL(6,1) NOT NULL DEFAULT '0.0' COMMENT '距离',
+  `cost` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '运费',
+  `tip` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '小费',
+  `sendTime` INT(11) NOT NULL DEFAULT '0' COMMENT '要求配送时间',
+  `status` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '0待接单 1已接单 2已完成 3已取消',
+  `addTime` INT(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
+  PRIMARY KEY (`id`)
+) COMMENT='第三方配送';
+CREATE TABLE `xhGhsStatOrderCount` (
+  `id` INT(11) NOT NULL AUTO_INCREMENT,
+  `time` INT(11) NOT NULL DEFAULT '0' COMMENT '月份',
+  `riseNum` INT(11) NOT NULL DEFAULT '0' COMMENT '增加数量',
+  `totalNum` INT(11) NOT NULL DEFAULT '0' COMMENT '总数量',
+  `ghsId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家id',
+  `shopId` INT(11) NOT NULL DEFAULT '0' COMMENT '门店id',
+  PRIMARY KEY (`id`),
+  KEY `ghs` (`ghsId`,`time`)
+) COMMENT='供货商月订单量,包括未付款'