shish 5 лет назад
Родитель
Сommit
c3a6a61844
2 измененных файлов с 127 добавлено и 98 удалено
  1. 110 97
      app/shop/controllers/OrderController.php
  2. 17 1
      sql.sql

+ 110 - 97
app/shop/controllers/OrderController.php

@@ -37,116 +37,129 @@ class OrderController extends BaseController
     {
         $post = Yii::$app->request->post();
         $needSend = isset($post['needSend']) && is_numeric($post['needSend']) ? $post['needSend'] : 1;
+        $orderType = $post['orderType'] ?? 1;
 
-        $goodsInfo = $post['goodsInfo'] ?? '';
-        $goodsInfoArr = json_decode($goodsInfo, true);
-        if (empty($goodsInfoArr)) {
-            util::fail('请选择商品');
-        }
-        //总的商品金额
-        $totalGoodsPrice = 0;
-        $orderGoods = [];
-        foreach ($goodsInfoArr as $key => $currentGoods) {
-            $currentGoodsId = $currentGoods['goodsId'];
-            $currentGoodsInfo = GoodsService::getGoodsInfo($currentGoodsId);
-            if (empty($currentGoodsInfo)) {
-                util::fail('没有找到商品');
-            }
-            $goodsStyleId = $currentGoods['goodsStyleId'];
-            $goodsNum = $currentGoods['goodsNum'];
-            //计算总金额
-            $unitPrice = $currentGoodsInfo['price'];
-            $goodsStyleList = isset($currentGoodsInfo['goodsStyleList']) ? $currentGoodsInfo['goodsStyleList'] : [];
-            if (!empty($goodsStyleId)) {
-                if (empty($goodsStyleList)) {
-                    util::fail('商品款式没有找到');
-                }
-                $styleIdList = array_keys($goodsStyleList);
-                if (in_array($goodsStyleId, $styleIdList) == false) {
-                    util::fail('商品款式没有找到!');
-                }
-                $unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
-            }
-            $goodsPrice = $unitPrice * $goodsNum;
-            $totalGoodsPrice = stringUtil::calcAdd($totalGoodsPrice, $goodsPrice);
-
-            $orderGoods[] = [
-                'goodsId' => $currentGoodsId,
-                'userId' => $this->adminId,
-                'merchantId' => $this->sjId,
-                'title' => $currentGoodsInfo['goodsName'],
-                'cover' => isset($goodsInfo['shortImgList']) && !empty($currentGoodsInfo['shortImgList']) ? current($currentGoodsInfo['shortImgList']) : '',
-                'unitPrice' => $unitPrice,
-                'num' => $goodsNum,
-                'goodsStyleName' => isset($currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
-                'goodsStyleId' => $goodsStyleId,
-                'createTime' => date("Y-m-d H:i:s"),
-            ];
-
-        }
-
-
-        $customId = $post['customId'] ?? 0;
-        if (!empty($customId)) {
-            $customId = $this->customId;
-        }
-        $post['customId'] = $customId;
-        $user = $this->custom;
-        $post['bookName'] = isset($user['name']) ? $user['name'] : '';
-        $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->sj);
         if (empty($defaultShopId)) {
             util::fail('没有找到门店');
         }
-        //计算运费
-        $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
-        $sendCost = 0;
-        //按距离计算运费并且客户要求送的
-        //运费计算方式
-        $freightType = 0;
-        if ($freightType == 0 && $needSend == 1) {
-            $lat = $post['latitude'];//收货人纬度
-            $lng = $post['longitude'];//收货人经度
-            $respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->sjExtend);
-            $sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
-        }
-        $post['sendCost'] = $sendCost;
         $post['merchantId'] = $this->sjId;
         $post['shopId'] = $defaultShopId;
-
-        $prePrice = stringUtil::calcAdd($sendCost, $totalGoodsPrice);
-
+        $post['payWay'] = $this->isWx == true ? 0 : 1;
+        $now = time();
+        $expireTime = $now + 1800;//订单30分钟后过期
+        $post['deadline'] = $expireTime;
+        $post['fromType'] = 1;//商城
+        $customId = $post['customId'] ?? 0;
+        if (!empty($customId)) {
+            $customId = $this->customId;
+        }
+        $post['customId'] = $customId;
         //非门店订单
         $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 = OrderClass::addOrder($post);
-        $orderId = $order['id'];
-        $orderSn = $order['orderSn'];
+        if ($orderType == 1) {
 
-        foreach ($orderGoods as $key => $val) {
-            $val['orderId'] = $orderId;
-            $val['orderSn'] = $orderSn;
-            OrderGoodsService::add($val);//创建订单商品列表
+            $goodsInfo = $post['goodsInfo'] ?? '';
+            $goodsInfoArr = json_decode($goodsInfo, true);
+            if (empty($goodsInfoArr)) {
+                util::fail('请选择商品');
+            }
+            //总的商品金额
+            $totalGoodsPrice = 0;
+            $orderGoods = [];
+            foreach ($goodsInfoArr as $key => $currentGoods) {
+                $currentGoodsId = $currentGoods['goodsId'];
+                $currentGoodsInfo = GoodsService::getGoodsInfo($currentGoodsId);
+                if (empty($currentGoodsInfo)) {
+                    util::fail('没有找到商品');
+                }
+                $goodsStyleId = $currentGoods['goodsStyleId'];
+                $goodsNum = $currentGoods['goodsNum'];
+                //计算总金额
+                $unitPrice = $currentGoodsInfo['price'];
+                $goodsStyleList = isset($currentGoodsInfo['goodsStyleList']) ? $currentGoodsInfo['goodsStyleList'] : [];
+                if (!empty($goodsStyleId)) {
+                    if (empty($goodsStyleList)) {
+                        util::fail('商品款式没有找到');
+                    }
+                    $styleIdList = array_keys($goodsStyleList);
+                    if (in_array($goodsStyleId, $styleIdList) == false) {
+                        util::fail('商品款式没有找到!');
+                    }
+                    $unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
+                }
+                $goodsPrice = $unitPrice * $goodsNum;
+                $totalGoodsPrice = stringUtil::calcAdd($totalGoodsPrice, $goodsPrice);
+
+                $orderGoods[] = [
+                    'goodsId' => $currentGoodsId,
+                    'userId' => $this->adminId,
+                    'merchantId' => $this->sjId,
+                    'title' => $currentGoodsInfo['goodsName'],
+                    'cover' => isset($goodsInfo['shortImgList']) && !empty($currentGoodsInfo['shortImgList']) ? current($currentGoodsInfo['shortImgList']) : '',
+                    'unitPrice' => $unitPrice,
+                    'num' => $goodsNum,
+                    'goodsStyleName' => isset($currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
+                    'goodsStyleId' => $goodsStyleId,
+                    'createTime' => date("Y-m-d H:i:s"),
+                ];
+
+            }
+
+            $user = $this->custom;
+            $post['bookName'] = isset($user['name']) ? $user['name'] : '';
+            $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['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
+            $sendCost = 0;
+            //按距离计算运费并且客户要求送的
+            //运费计算方式
+            $freightType = 0;
+            if ($freightType == 0 && $needSend == 1) {
+                $lat = $post['latitude'];//收货人纬度
+                $lng = $post['longitude'];//收货人经度
+                $respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->sjExtend);
+                $sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
+            }
+            $post['sendCost'] = $sendCost;
+
+            $prePrice = stringUtil::calcAdd($sendCost, $totalGoodsPrice);
+
+            //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
+            $sourceType = $this->isWx ? 0 : 1;
+            if (httpUtil::isMiniProgram()) {
+                $sourceType = 2;
+            }
+            $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
+            $actPrice = $discountData['price'];
+            $post['discountType'] = $discountData['discountType'];
+            $post['discountAmount'] = $discountData['discountAmount'];
+            $post['prePrice'] = $prePrice;
+            $post['actPrice'] = $actPrice;
+            $order = OrderClass::addOrder($post);
+            $orderId = $order['id'];
+            $orderSn = $order['orderSn'];
+
+            foreach ($orderGoods as $key => $val) {
+                $val['orderId'] = $orderId;
+                $val['orderSn'] = $orderSn;
+                OrderGoodsService::add($val);//创建订单商品列表
+            }
+        } else {
+            $productData = $post['product'] ?? '';
+            $product = json_decode($productData, true);
+
+
+            $order = OrderClass::addOrder($post);
+            $orderId = $order['id'];
+            $orderSn = $order['orderSn'];
         }
 
         util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId, 'orderId' => $orderId]);

+ 17 - 1
sql.sql

@@ -1140,4 +1140,20 @@ ALTER TABLE xhItem ADD classId INT NOT NULL DEFAULT 0 COMMENT '平台分类id' A
 ALTER TABLE `xhItem`
 MODIFY COLUMN `addTime`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
 MODIFY COLUMN `updateTime`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间';
-ALTER TABLE xhOrderGoods ADD orderSn CHAR(20) NOT NULL DEFAULT '' COMMENT '' AFTER `orderId`;
+ALTER TABLE xhOrderGoods ADD orderSn CHAR(20) NOT NULL DEFAULT '' COMMENT '' AFTER `orderId`;
+ALTER TABLE xhOrder ADD packingFee DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '包装费' AFTER `anonymity`;
+ALTER TABLE xhOrder ADD orderType TINYINT NOT NULL DEFAULT 1 COMMENT '1成品订单 2花材订单' AFTER `goodsNum`;
+DROP TABLE IF EXISTS `xhOrderItem`;
+CREATE TABLE IF NOT EXISTS `xhOrderItem`(
+  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+  `orderSn` CHAR(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '订单编号',
+  `itemId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家花材id',
+  `productId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家商品id',
+  `smallUnit` SMALLINT(6) NOT NULL DEFAULT '2' COMMENT '小单位,支,个,条',
+  `bigUnit` SMALLINT(6) NOT NULL DEFAULT '1' COMMENT '大单位,扎,箱,包',
+  `price` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '总价格',
+  `num` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '总数量',
+  `bigNum` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '大单位数量,扎,包,箱',
+  `smallNum` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '小单位数量,支,个,条',
+  `ratio` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '大小单位转换比例,1扎多少支,1包多少支'
+)COMMENT='零售订单的花材';