shish 4 лет назад
Родитель
Сommit
7cdc42e37b

+ 0 - 2
app-hd/controllers/OrderController.php

@@ -73,8 +73,6 @@ class OrderController extends BaseController
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {
-            //批量验证商品
-            GoodsClass::batchValid($productList, $this->mainId);
             $post['product'] = $productList;
             $post['deadline'] = date("Y-m-d H:i:s", strtotime('+360 day'));
             $return = OrderService::createFinishOrder($post, $custom, $hasPay);

+ 17 - 83
biz-hd/order/classes/OrderClass.php

@@ -142,7 +142,7 @@ class OrderClass extends BaseClass
     }
 
     //第三方支付后回调处理流程 shish 2021.4.30
-    public static function thirdPay($payWay, $orderSn, $totalFee, $attach)
+    public static function thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId)
     {
         $order = self::getByCondition(['orderSn' => $orderSn], true);
         if (empty($order)) {
@@ -156,40 +156,21 @@ class OrderClass extends BaseClass
             util::fail($msg);
         }
 
-        //临时解决微信一秒内通知二次问题
         $id = $order->id;
         $order = self::getLockById($id);
-
         $date = date("Y-m-d H:i:s");
         $order->payTime = $date;
+        $order->thirdNo = $transactionId;
         $order->onlinePay = dict::getDict('onlinePay', 'yes');
         $order->save();
-        self::complete($order, $payWay);
-        //订单全部流程走完了再通知
-        if ($order->fromType == dict::getDict("fromType", "shop")) {
-            $shopAdminIds = \bizGhs\shop\classes\ShopAdminClass::getRemindAdminIdsByShopId($order->shopId);
-            if ($shopAdminIds) {
-                foreach ($shopAdminIds as $v) {
-                    WsService::arrivalNotice($v, $order->actPrice, $order->payWay);
-                }
-            }
-        }
-    }
 
-    //员工开单选择付款方式 shish 2021.5.4
-    public static function staffKdPay($payWay, $orderSn)
-    {
-        $order = self::getByCondition(['orderSn' => $orderSn], true);
-        if (empty($order)) {
-            $msg = "没有找到零售订单 orderSn:{$orderSn}";
-            Yii::info($msg);
-            util::fail($msg);
-        }
-        self::complete($order, $payWay);
+        self::payAfter($order, $payWay);
+
     }
 
+
     //订单完成 shish 2021.4.20
-    public static function complete($order, $payWay)
+    public static function payAfter($order, $payWay)
     {
         if (empty($order)) {
             util::fail('没有找到订单');
@@ -197,24 +178,17 @@ class OrderClass extends BaseClass
         if (isset($order->status) == false || $order->status != self::ORDER_STATUS_UN_PAY) {
             util::fail('订单不是待付款状态');
         }
-        $orderGoods = OrderGoodsClass::getAllByCondition(['orderId' => $order->id], null, '*');
-
+        $orderId = $order->id ?? 0;
         $order->status = self::ORDER_STATUS_UN_SEND;
         $order->currentFlow = 2;
         $order->payWay = $payWay;
         $order->save();
 
-        //下单完成,开始制单
-        $current = time();
-        $orderId = $order->id;
-        $orderSn = $order->orderSn;
-        OrderSendClass::placeOrder(['orderId' => $orderId, 'payTime' => $current, 'orderSn' => $orderSn]);
 
         $realPrice = $order->realPrice ?? 0;
         $shopId = $order->shopId;
         $shop = ShopClass::getLockById($shopId);
         if (empty($shop)) {
-            Yii::info("没有找到门店 OrderClass::complete() orderId:{$order->id}");
             util::fail('没有找到门店');
         }
         $shop->unSendOrder += 1;
@@ -227,11 +201,7 @@ class OrderClass extends BaseClass
         $shopAdminId = $order->shopAdminId ?? 0;
         $shopAdminName = $order->shopAdminName ?? '';
         $sjId = $order->sjId;
-        $event = '客户下单';
-        if (!empty($shopAdminId)) {
-            $event = '员工开单';
-        }
-
+        $event = !empty($shopAdminId) ? '员工开单' : '客户下单';
         $capital = [
             'capitalType' => $capitalType,
             'relateId' => $orderId,
@@ -246,61 +216,25 @@ class OrderClass extends BaseClass
             'amount' => $realPrice,
         ];
         ShopCapitalClass::addCapital($capital);
-
         //每天和每月收入增加
         StatIncomeClass::updateOrInsert($shop, $realPrice);
         //今日订单+1
         StatOrderClass::updateOrInsert($shop);
 
-        //二维码收款订单存在没有商品的情况
-        if (!empty($orderGoods)) {
-            // 扣库存
-            self::decGoodsStock($orderGoods);
-            // 增加销量
-            self::updateGoodsActualSold($orderGoods);
+        //客户在线支付下单增加商家可提现余额
+        if (isset($order->onlinePay) && $order->onlinePay == dict::getDict('onlinePay', 'yes')) {
+            $amount = $order->actPrice;
+            ShopClass::customKdAddBalance($shop, $amount, $order, $capitalType);
         }
-
-        if (isset($order->shopAdminId) == false) {
-            util::fail('没有员工字段');
-        }
-        if (isset($order->fromType) == false) {
-            util::fail('没有来源字段');
+        if (in_array($order->fromType, [dict::getDict("fromType", "shop"), dict::getDict("fromType", "friend")])) {
+            //您有新的收入提醒
+            WxMessageClass::gatheringIncomeInform($shop, $order);
         }
-
-        if (!empty($order->shopAdminId)) {
-            //员工开单,自取订单,直接完成
-            if ($order->sendType == self::SEND_TYPE_NO) {
-                OrderSendClass::withoutSend($order);
-            }
-        } else {
-            //客户在线支付下单增加商家可提现余额
-            if (isset($order->onlinePay) && $order->onlinePay == dict::getDict('onlinePay', 'yes')) {
-                $amount = $order->actPrice;
-                ShopClass::customKdAddBalance($shop, $amount, $order, $capitalType);
-            }
-            //门店和朋友圈订单并且没有填写收花人的直接将订单置为自取并且是完成状态
-            if (in_array($order->fromType, [dict::getDict("fromType", "shop"), dict::getDict("fromType", "friend")])) {
-                if (isset($order->receiveMobile) && isset($order->address)) {
-                    if (empty($order->receiveMobile) && empty($order->address)) {
-                        OrderSendClass::withoutSend($order);
-                    }
-                }
-                //您有新的收入提醒(门店订单)
-                WxMessageClass::gatheringIncomeInform($shop, $order);
-            }
-        };
-        //来自商城的订单通知 linqh 2021.5.19
         if ($order->fromType == dict::getDict("fromType", "mall")) {
-            $shopIdAdminIds = \bizGhs\shop\classes\ShopAdminClass::getRemindAdminIdsByShopId($shopId);
-            //语音通知
-            if ($shopIdAdminIds) {
-                foreach ($shopIdAdminIds as $v) {
-                    WsService::newOrderNotice($v);
-                }
-            }
-            //新订单微信通知
+            //来自商城的新订单微信通知
             WxMessageClass::hdNewOrderInform($shop, $order);
         }
+
     }
 
     //转化出送到时间 ssh 2020.3.15

+ 14 - 0
biz-hd/order/classes/OrderItemClass.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace bizHd\order\classes;
+
+use common\components\business;
+use Yii;
+use bizHd\base\classes\BaseClass;
+
+class OrderItemClass extends BaseClass
+{
+
+	public static $baseFile = '\bizHd\order\models\OrderItem';
+
+}

+ 14 - 0
biz-hd/order/models/OrderItem.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace bizHd\order\models;
+
+use bizHd\base\models\Base;
+
+class OrderItem extends Base
+{
+	
+	public static function tableName()
+	{
+		return 'xhOrderItem';
+	}
+}

+ 57 - 17
biz-hd/order/services/OrderService.php

@@ -7,19 +7,15 @@ use biz\sj\services\SjCapitalService;
 use biz\sj\services\MerchantService;
 use bizHd\custom\classes\CustomClass;
 use bizHd\order\classes\OrderClass;
-use bizHd\order\models\Order;
-use bizHd\promote\services\CouponRightService;
+use bizHd\order\classes\OrderGoodsClass;
+use bizHd\order\classes\OrderItemClass;
 use bizHd\promote\services\CouponService;
 use bizHd\user\classes\UserAssetClass;
-use bizHd\user\services\UserService;
 use common\components\dict;
-use common\components\error;
 use common\components\imgUtil;
 use common\components\stringUtil;
-use common\components\validate;
 use common\components\util;
 use Yii;
-use linslin\yii2\curl;
 
 class OrderService extends BaseService
 {
@@ -29,28 +25,72 @@ class OrderService extends BaseService
     public static function createFinishOrder($data, $custom, $hasPay = 1)
     {
         $payWay = $data['payWay'] ?? dict::getDict('payWay', 'wxPay');
+        $requestSide = $data['requestSide'] ?? 0;
+        if ($requestSide == 1) {
+            //收银台开单成品必须要有库存
+            $groupId = $data['groupId'] ?? 0;
+            if (!empty($groupId)) {
+                $totalPrice = 0;
+            } else {
+                $product = $data['product'] ?? [];
+                if (empty($product)) {
+                    util::fail('没有商品');
+                }
+                $totalPrice = 0;
+                foreach ($product as $key => $val) {
+                    if (isset($val['property']) == false) {
+                        util::fail('没有找到产品属性');
+                    }
+                    $currentPrice = $val['price'] ?? 0;
+                    $totalPrice = bcadd($totalPrice, $currentPrice, 2);
+                    $property = $val['property'];
+                    if ($property == dict::getDict('property', 'goods')) {
+
+                    }
+                    if ($property == dict::getDict('property', 'item')) {
+
+                    }
+                }
+            }
+            $sendCost = $data['sendCost'] ?? 0;
+            $totalPrice = bcadd($totalPrice, $sendCost, 2);
+            $modifyPrice = $data['modifyPrice'] ?? 0;
+            if ($modifyPrice > $totalPrice) {
+                //人工资材包装费
+                $data['labourCost'] = bcsub($modifyPrice, $totalPrice, 2);
+            }
+            if ($modifyPrice < $totalPrice) {
+                //优惠
+                $data['discountType'] = dict::getDict('discountType', 'discount');
+                $discountAmount = bcsub($totalPrice, $modifyPrice, 2);
+                $data['discountAmount'] = $discountAmount;
+            }
 
-        $returnOrder = OrderClass::addOrder($data);
+            $orderGoods = [];
+            $orderItem = [];
+            OrderGoodsClass::add();
+            OrderItemClass::add();
+
+            $addData = [
+                'prePrice' => $totalPrice,
+                'actPrice' => $modifyPrice,
+                'realPrice' => $modifyPrice,
+            ];
+            $returnOrder = OrderClass::addOrder($addData);
 
-        $mallData = [
+        } else {
+            //非收银台开单成品没有库存则生成制作单
+        }
 
-        ];
-        $purchase = \bizMall\order\classes\OrderClass::addOrder($mallData);
 
         //欠款和已付款的直接完成
         if (in_array($hasPay, [dict::getDict('hasPay', 'payed'), dict::getDict('hasPay', 'debt')])) {
-            //顺序不能换
-            \bizMall\order\services\OrderService::payAfter($purchase, $payWay);
-            self::payAfter($returnOrder, $payWay);
+            OrderClass::payAfter($returnOrder, $payWay);
         }
 
         return $returnOrder;
     }
 
-    public static function payAfter($order, $payWay)
-    {
-
-    }
 
     //添加订单
     public static function addOrder($data)

+ 7 - 0
common/components/dict.php

@@ -22,6 +22,13 @@ class dict
         'hasPayMap' => [
 
         ],
+        //产品属性
+        'property' => [
+            //成品
+            'goods' => 0,
+            //花材
+            'item' => 1,
+        ],
 
         //批发店囤货时显示给零售库存的最高值
         'showMaxStock' => 260,

+ 1 - 1
common/components/payUtil.php

@@ -79,7 +79,7 @@ class payUtil
                     break;
                 case dict::getDict('capitalType', 'xhOrder', 'id'):
                     //花粉下单
-                    OrderClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
+                    OrderClass::thirdPay($payWay, $orderSn, $totalFee, $attach,$transactionId);
                     $transaction->commit();
                     //收款声音播放 shish 202010726
                     $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);

+ 50 - 1
sql.txt

@@ -322,6 +322,7 @@ ADD INDEX `idx_mainId` (`mainId`) ;
 ===============花材相关表结构变更end========
 
 
+
 ==========客户的花店 shish 20220316
 
 DROP TABLE IF EXISTS `xhHd`;
@@ -354,4 +355,52 @@ CREATE TABLE `xhHd` (
   `inTurn` INT(10) NOT NULL DEFAULT '100' COMMENT '排序',
   `addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
   `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间'
-) COMMENT='客户的花店';
+) COMMENT='客户的花店';
+
+ALTER TABLE xhOrder ADD `thirdNo` CHAR(80) NOT NULL DEFAULT '' COMMENT '支付回调编号,微信支付回调的transaction_id' AFTER `orderType`;
+ALTER TABLE xhOrder ADD `labourCost` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '人工和资材和包装费' AFTER `sendCost`;
+
+DROP TABLE IF EXISTS `xhOrderItem`;
+CREATE TABLE `xhOrderItem` (
+  `id` INT(11) NOT NULL AUTO_INCREMENT,
+  `name` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '名称',
+  `cover` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '封面',
+  `ratio` TINYINT(4) NOT NULL DEFAULT 0 COMMENT '大小单位比例',
+  `unitType` TINYINT NOT NULL DEFAULT 0 COMMENT '单位类型 0大单位 1小单位',
+  `unitName` CHAR(10) NOT NULL DEFAULT '' COMMENT '单位名称',
+  `unitId` INT NOT NULL DEFAULT 0 COMMENT '单位id',
+  `unitPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '单价',
+  `num` INT NOT NULL DEFAULT 0 COMMENT '当前单位数量',
+  `orderId` INT(11) NOT NULL DEFAULT '0' COMMENT '订单id',
+  `orderSn` CHAR(20) NOT NULL DEFAULT '' COMMENT '订单编号',
+  `itemId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家花材id',
+  `ptItemId` INT NOT NULL DEFAULT 0 COMMENT '平台花材id',
+  `totalNum` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '数量',
+  `totalPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '总价',
+  `customId` INT(11) NOT NULL DEFAULT '0' COMMENT '客户id',
+  `hdId` INT NOT NULL DEFAULT 0 COMMENT '花店id',
+  `sjId` INT(11) NOT NULL DEFAULT '0' COMMENT '商户id',
+  `shopId` INT NOT NULL DEFAULT 0 COMMENT '门店id',
+  `addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+  `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
+  PRIMARY KEY (`id`)
+)COMMENT='零售订单花材详情';
+DROP TABLE IF EXISTS `xhOrderGoods`;
+CREATE TABLE `xhOrderGoods` (
+  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '订单id',
+  `orderId` INT(11) NOT NULL DEFAULT '0' COMMENT '订单id',
+  `orderSn` CHAR(20) NOT NULL DEFAULT '' COMMENT '订单编号',
+  `goodsId` INT(11) NOT NULL DEFAULT '0' COMMENT '商品id,备用字段',
+  `customId` INT(11) NOT NULL DEFAULT '0' COMMENT '客户id',
+  `hdId` INT NOT NULL DEFAULT 0 COMMENT '花店id',
+  `sjId` INT(11) NOT NULL DEFAULT '0' COMMENT '商户id',
+  `shopId` INT NOT NULL DEFAULT 0 COMMENT '门店id',
+  `name` VARCHAR(200) NOT NULL DEFAULT '' COMMENT '名称',
+  `cover` VARCHAR(200) NOT NULL DEFAULT '' COMMENT '封面',
+  `unitPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '单价',
+  `num` INT(11) NOT NULL DEFAULT '0' COMMENT '数量',
+  `totalPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '总价',
+  `addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+  `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
+  PRIMARY KEY (`id`)
+) COMMENT='零售订单商品明细';