Explorar el Código

下单与采购

shish hace 5 años
padre
commit
ff6e0f9d48

+ 21 - 75
app/ghs/controllers/OrderController.php

@@ -8,6 +8,7 @@ use biz\merchant\services\MerchantExtendService;
 use biz\merchant\services\MerchantService;
 use bizGhs\merchant\services\ShopService;
 use biz\order\classes\OrderSendClass;
+use bizGhs\order\classes\OrderClass;
 use bizGhs\order\services\OrderService;
 use biz\saas\services\RegionService;
 use biz\user\services\UserService;
@@ -26,95 +27,40 @@ class OrderController extends BaseController
     //商城下单操作 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 = Yii::$app->request->post();
+        $post['adminId'] = 0;
         $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'];
-
+        $post['ghsId'] = $this->ghsId;
+        $post['shopId'] = 0;
         $now = time();
         $expireTime = $now + 1800;//订单30分钟后过期
         $post['deadline'] = $expireTime;
         $post['fromType'] = 1;//商城
         $post['prePrice'] = $prePrice;
         $post['actPrice'] = $actPrice;
-        $order = OrderService::addOrder($post);
+        $order = OrderClass::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"),
+        //花材商品
+        $itemData = [
+            [
+                'orderId'=>$orderId,
+                'itemId'=>0,
+                'itemInfoId'=>0,
+                'unitPrice'=>0.01,
+                'unitNum'=>0,
+                'num'=>0,
+            ],
         ];
         //OrderGoodsService::add($data);//创建订单商品列表
-        util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId]);
+        util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice]);
+
+
     }
 
     //下单要用到的相关信息 shish 2019.12.6

+ 31 - 0
app/shop/controllers/PurchaseController.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace shop\controllers;
+
+use Yii;
+use common\components\util;
+
+class PurchaseController extends BaseController
+{
+
+    //生成采购单 shish 2021.1.17
+    public function actionCreateOrder()
+    {
+
+
+        $itemData = [
+            [
+                'orderId'=>$orderId,
+                'itemId'=>0,
+                'itemInfoId'=>0,
+                'unitPrice'=>0.01,
+                'unitNum'=>0,
+                'num'=>0,
+            ],
+        ];
+        //OrderGoodsService::add($data);//创建订单商品列表
+
+
+    }
+
+}

+ 8 - 7
biz-ghs/order/classes/OrderClass.php

@@ -57,21 +57,22 @@ class OrderClass extends BaseClass
     public static function addOrder($data)
     {
         $date = date("Y-m-d H:i:s");
-        $merchantId = $data['merchantId'];
-        $data['orderSn'] = stringUtil::generateOrderNo($merchantId, $data['adminId']);
+        $ghsId = $data['ghsId'] ?? 0;
+        $adminId = $data['adminId'] ?? 0;
+        $data['orderSn'] = stringUtil::generateOrderNo($ghsId, $adminId);
         $data['payStatus'] = 0;
         $data['createTime'] = $date;
         $data['addTime'] = time();
 
         $month = date("Ym");
-        $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
+        $riseNum = StatOrderCountClass::addOrder($month, $ghsId);
         //将花店每月的总订单数作为编号
         $data['sendNum'] = $riseNum;
         $data['totalFlow'] = OrderClass::ORDER_TOTAL_FLOW;
         $return = self::add($data);
 
         //全部订单+1,待付款订单+1
-        $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
+        $merchantAsset = MerchantAssetClass::getByMerchantId($ghsId, true);
         $merchantAsset->unPayOrder += 1;
         $merchantAsset->totalOrder += 1;
         $merchantAsset->save();
@@ -194,10 +195,10 @@ class OrderClass extends BaseClass
         self::updateById($orderId, $updateData);
         //发货流程的完成下单
         OrderSendClass::placeOrder(['orderId' => $orderId, 'payTime' => $now]);
-        $merchantId = $order['merchantId'];
-        $asset = MerchantAssetClass::getByMerchantId($merchantId);
+        $ghsId = $order['ghsId'];
+        $asset = MerchantAssetClass::getByMerchantId($ghsId);
         //增加订单数
-        StatOrderClass::addOrder($merchantId, $asset);
+        StatOrderClass::addOrder($ghsId, $asset);
         //如果门店和朋友圈订单并且没有填写收花人的直接将订单置为自取并且是完成状态
         if (isset($order['fromType']) && in_array($order['fromType'], [0, 2])) {
             if (isset($order['receiveMobile']) && isset($order['receiveAddress'])) {

+ 53 - 1
sql.sql

@@ -533,4 +533,56 @@ ALTER TABLE xhItem MODIFY unitNum TINYINT(4) NOT NULL DEFAULT '0' COMMENT '每
 ALTER TABLE `xhGhsShopAdmin` ADD `super` TINYINT NOT NULL DEFAULT 0 COMMENT '是否店长或超级管理员0不是1是' AFTER `roleId`;
 ALTER TABLE `xhShopAdmin` ADD `super` TINYINT NOT NULL DEFAULT 0 COMMENT '是否店长或超级管理员0不是1是' AFTER `roleId`;
 ALTER TABLE `xhGhsShop` ADD adminId INT NOT NULL DEFAULT 0 COMMENT '店长id' AFTER `ghsId`;
-ALTER TABLE `xhShop` ADD adminId INT NOT NULL DEFAULT 0 COMMENT '店长id' AFTER `merchantId`;
+ALTER TABLE `xhShop` ADD adminId INT NOT NULL DEFAULT 0 COMMENT '店长id' AFTER `merchantId`;
+ALTER TABLE xhGhsOrder MODIFY `sendSide` TINYINT NOT NULL DEFAULT 0 COMMENT '配送方 0未选择 1达达2顺丰同城3闪送4美团';
+ALTER TABLE xhOrder MODIFY `sendSide` TINYINT NOT NULL DEFAULT 0 COMMENT '配送方 0未选择 1达达2顺丰同城3闪送4美团';
+ALTER TABLE xhGhsOrder ADD `receiveProvince` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '收货地址 省' AFTER `shopId`;
+ALTER TABLE xhGhsOrder ADD `receiveCity` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '收货地址 市' AFTER `receiveProvince`;
+ALTER TABLE xhGhsOrder ADD `receiveDist` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '收货地址 区县市' AFTER `receiveCity`;
+ALTER TABLE xhGhsOrder ADD `receiveAddress` VARCHAR(300) NOT NULL DEFAULT '' COMMENT '收货地址 详细街道地址' AFTER `receiveDist`;
+ALTER TABLE xhGhsOrder ADD `receiveFloor` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '收货地址 楼号门牌号' AFTER `receiveAddress`;
+ALTER TABLE xhGhsOrder ADD `receiveFullAddress` VARCHAR(400) NOT NULL DEFAULT '' COMMENT '完整收货地址' AFTER `receiveFloor`;
+ALTER TABLE xhGhsOrder ADD `receiveLong` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '收货的经度' AFTER `receiveFullAddress`;
+ALTER TABLE xhGhsOrder ADD `receiveLat` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '收货的纬度' AFTER `receiveLong`;
+ALTER TABLE `xhGhsOrder` ADD sendTime INT NOT NULL DEFAULT 0 COMMENT '配送时间' AFTER `sendSide`;
+ALTER TABLE `xhGhsOrder` ADD `sendCost` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '运费' AFTER `sendTime`;
+ALTER TABLE `xhGhsOrder` ADD `sendTip` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '运费里增加的小费' AFTER `sendCost`;
+ALTER TABLE `xhGhsOrder` ADD `sendNum` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '配送编号,方便寻找订单对应的花束' AFTER `sendTip`;
+ALTER TABLE xhGhsOrderItem ADD itemInfoId INT NOT NULL DEFAULT 0 COMMENT '商家商品id' AFTER `itemId`;
+INSERT INTO xhUnit VALUES(NULL,'扎',1610881951,1610881951);
+INSERT INTO xhUnit VALUES(NULL,'支',1610881951,1610881951);
+ALTER TABLE xhGhsOrderItem ADD smallUnit SMALLINT NOT NULL DEFAULT 2 COMMENT '小单位,支,个,条' AFTER `itemInfoId`;
+ALTER TABLE xhGhsOrderItem ADD bigUnit SMALLINT NOT NULL DEFAULT 1 COMMENT '大单位,扎,箱,包' AFTER `smallUnit`;
+ALTER TABLE xhGhsOrderItem ADD smallUnitName CHAR(5) NOT NULL DEFAULT '支' COMMENT '小单位中文名' AFTER `smallUnit`;
+ALTER TABLE xhGhsOrderItem ADD bigUnitName CHAR(5) NOT NULL DEFAULT '扎' COMMENT '大单位中文名' AFTER `bigUnit`;
+ALTER TABLE `xhGhsOrderItem` DROP COLUMN `smallUnitName`;
+ALTER TABLE `xhGhsOrderItem` DROP COLUMN `bigUnitName`;
+ALTER TABLE xhGhsOrderItem DROP COLUMN `ghsId`;
+ALTER TABLE xhGhsOrderItem DROP COLUMN `adminId`;
+CREATE TABLE `xhPurchase` (
+  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
+  `ghsId` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '供货商ID',
+  `ghsShopId` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '供货商门店ID',
+  `shopId` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '门店ID',
+  `status` TINYINT(2) NOT NULL DEFAULT '0' COMMENT '订单状态 1待付款,待确认,2待配送,3配送中,4已完成',
+  `debt` TINYINT NOT NULL DEFAULT 0 COMMENT '欠款 1是 0没有,已结清',
+  `addTime` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
+  `updateTime` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '最后修改时间',
+  PRIMARY KEY (`id`)
+) COMMENT='采购单';
+CREATE TABLE `xhPurchaseItem` (
+  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
+  `orderId` INT NOT NULL DEFAULT 0 COMMENT '采购单id',
+  `itemId` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '花材ID',
+  `num` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '花材数量',
+  `unitPrice` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '采购总价',
+  `price` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '采购总价',
+  PRIMARY KEY (`id`)
+) COMMENT='采购单详情';
+ALTER TABLE `xhPurchase` ADD getType TINYINT NOT NULL DEFAULT 1 COMMENT '取货方式 1配送 2自取' AFTER `shopId`;
+ALTER TABLE `xhPurchase` ADD sendTime INT NOT NULL DEFAULT 0 COMMENT '配送时间' AFTER `getType`;
+ALTER TABLE `xhPurchase` ADD sendCost DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '运费' AFTER `sendTime`;
+ALTER TABLE `xhPurchase` ADD `itemPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '花材总金额' AFTER `shopId`;
+ALTER TABLE `xhPurchase` ADD `prePrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '应付款,原价,未修改价格,打折前' AFTER `itemPrice`;
+ALTER TABLE `xhPurchase` ADD `actPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '实际付款,实价,修改后价格,打折后' AFTER `prePrice`;
+ALTER TABLE `xhPurchase` ADD remark VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '备注' AFTER `debt`;