Browse Source

Merge branch 'master' of http://git.huaml.com/zhh/huahuibao

sorry 5 years ago
parent
commit
0d01ffc3b0

+ 6 - 7
app-ghs/controllers/NoticeController.php

@@ -6,6 +6,7 @@ use bizGhs\express\services\DadaExpressServices;
 use bizGhs\order\classes\OrderClass;
 use bizGhs\order\classes\OrderExpressClass;
 use bizGhs\order\classes\OrderSendClass;
+use bizGhs\order\services\OrderService;
 use common\components\dict;
 use common\components\pay;
 use Yii;
@@ -160,15 +161,15 @@ class NoticeController extends PublicController
         $orderSn = $postData['order_id'];
         $sign = $postData['signature']; //签名验证?没有
         //判断订单是否存在
-        $orderInfo = OrderClass::getByOrderSn($orderSn);
+        $orderInfo = OrderClass::getByOrderSn($orderSn, true);
         if (!$orderInfo) {
             Yii::warning("dada callback error: 订单不不存在: " . $orderSn);
             util::end();
         }
         $orderStatus = $postData['order_status'];
-        $orderSn = $orderInfo['orderSn'];
-        $sjId = $orderInfo['merchantId'] ?? 0;
-        $sendTime = $orderInfo['sendTime'];
+        $orderSn = $orderInfo->orderSn;
+        $sjId = $orderInfo->merchantId ?? 0;
+        $sendTime = $orderInfo->sendTime;
 
         switch ($orderStatus) {
             case DadaExpressServices::ORDER_WAIT_ACCEPT:
@@ -188,9 +189,7 @@ class NoticeController extends PublicController
                 break;
             case DadaExpressServices::ORDER_COMPLETE:
                 //订单完成 todo
-                OrderExpressClass::reach($orderInfo);
-                OrderSendClass::reach($orderInfo);
-                OrderClass::reach($orderInfo);
+                OrderService::reach($orderInfo);
                 break;
             case DadaExpressServices::ORDER_CANCEL:
                 //取消 todo

+ 20 - 16
app-ghs/controllers/OrderController.php

@@ -3,9 +3,9 @@
 namespace ghs\controllers;
 
 use bizGhs\express\services\DadaExpressServices;
+use bizHd\purchase\classes\PurchaseClass;
 use bizHd\wx\classes\WxOpenClass;
 use bizGhs\custom\classes\CustomClass;
-use bizGhs\merchant\services\ShopService;
 use bizGhs\order\classes\OrderClass;
 use bizGhs\order\services\OrderService;
 use bizHd\saas\services\RegionService;
@@ -127,7 +127,7 @@ class OrderController extends BaseController
     {
         $get = Yii::$app->request->get();
         $id = $get['id'] ?? 0;
-        $info = OrderClass::getOrderInfo($id);
+        $info = OrderService::getOrderInfo($id);
         OrderClass::valid($info, $this->shopId);
         OrderClass::debt($info, $this->shop);
         util::complete();
@@ -209,19 +209,23 @@ class OrderController extends BaseController
     {
         $get = Yii::$app->request->get();
         $id = $get['id'] ?? 0;
-        $info = OrderClass::getOrderInfo($id, true, true, true, false);
+        $info = OrderService::getOrderInfo($id, true, true, true, false);
         OrderClass::valid($info, $this->shopId);
         util::success($info);
     }
 
-    //自取免发货流程处理 ssh 2021.1.22
+    //自取免发货流程处理 ssh 2021.1.22
     public function actionWithoutSend()
     {
         $get = Yii::$app->request->get();
         $id = $get['id'] ?? 0;
-        $info = OrderClass::getOrderInfo($id);
+        $info = OrderService::getById($id, true);
         OrderClass::valid($info, $this->shopId);
-        OrderClass::withoutSend($info);
+
+        $purchaseId = $info->purchaseId;
+        $purchase = PurchaseClass::getById($purchaseId, true);
+
+        OrderService::withoutSend($info, $purchase);
         util::complete();
     }
 
@@ -230,8 +234,8 @@ class OrderController extends BaseController
     {
         $get = Yii::$app->request->get();
         $id = isset($get['id']) ? $get['id'] : 0;
-        $info = OrderClass::getOrderInfo($id);
-        OrderClass::valid($info, $this->shopId);
+        $info = OrderClass::getById($id, true);
+        OrderClass::valid($info->attributes, $this->shopId);
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
@@ -287,7 +291,7 @@ class OrderController extends BaseController
             }
         }
         //更新订单表
-        $info = OrderClass::getOrderInfo($orderId);
+        $info = OrderService::getOrderInfo($orderId);
         OrderClass::valid($info, $this->shopId);
         $expressAddInfo = [
             'customName' => $customName,
@@ -319,8 +323,8 @@ class OrderController extends BaseController
     {
         $get = Yii::$app->request->get();
         $id = isset($get['id']) ? $get['id'] : 0;
-        $info = OrderClass::getOrderInfo($id);
-        OrderClass::valid($info, $this->shopId);
+        $info = OrderService::getById($id, true);
+        OrderClass::valid($info->attributes, $this->shopId);
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
@@ -339,12 +343,12 @@ class OrderController extends BaseController
     {
         $get = Yii::$app->request->get();
         $id = isset($get['id']) ? $get['id'] : 0;
-        $info = OrderClass::getOrderInfo($id);
-        OrderClass::valid($info, $this->shopId);
+        $info = OrderClass::getById($id, true);
+        OrderClass::valid($info->attributes, $this->shopId);
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-            OrderClass::reach($info);
+            OrderService::reach($info);
             $transaction->commit();
         } catch (\Exception $exception) {
             $transaction->rollBack();
@@ -358,10 +362,10 @@ class OrderController extends BaseController
     public function actionOrderRelate()
     {
         $regionTree = RegionService::tree();
-        $shop = ShopService::getDefaultShop($this->sj);
+        $shop = $this->shop;
         $freight = ['first' => 5, 'add' => 2];
         $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
-        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->sj];
+        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
         util::success($out);
     }
 

+ 2 - 1
app-ghs/controllers/OrderItemController.php

@@ -4,6 +4,7 @@ namespace ghs\controllers;
 
 use bizGhs\order\classes\OrderClass;
 use bizGhs\order\classes\OrderItemClass;
+use bizGhs\order\services\OrderService;
 use bizGhs\product\classes\ProductClass;
 use common\components\util;
 use Yii;
@@ -23,7 +24,7 @@ class OrderItemController extends BaseController
         //检查花材是否都是同家门店的
         ProductClass::valid($product, $this->shopId);
 
-        $info = OrderClass::getOrderInfo($id);
+        $info = OrderService::getOrderInfo($id);
         OrderClass::valid($info, $this->shopId);
 
         //添加修改花材

+ 4 - 4
app-ghs/controllers/OrderSendController.php

@@ -12,18 +12,18 @@ use common\components\util;
 class OrderSendController extends BaseController
 {
 
-    //鍙戣揣 ssh 2019.12.16
+    //发货 ssh 2019.12.16
     public function actionDetail()
     {
         $id = Yii::$app->request->get('id', 0);
         $order = OrderService::getById($id);
         OrderService::valid($order, $this->shopId);
-        //鍙戣揣鍒楄〃
+        //发货列表
         $list = OrderSendService::sendList($order);
         util::success($list);
     }
 
-    //鍙戣揣 ssh 2019.12.17
+    //发货 ssh 2019.12.17
     public function actionDeliver()
     {
         $post = Yii::$app->request->post();
@@ -35,7 +35,7 @@ class OrderSendController extends BaseController
         OrderSendService::deliver($post);
     }
 
-    //閫佽揪 ssh 2019.12.17
+    //送达 ssh 2019.12.17
     public function actionReach()
     {
         $post = Yii::$app->request->post();

+ 2 - 2
app-hd/controllers/ConsoleController.php

@@ -43,7 +43,7 @@ class ConsoleController extends BaseController
                     $num = ceil($remain / 86400);
                     $title = "您的试用期还有{$num}天,请及时续费";
                 }
-                $notice = array_merge($notice, [['title' => $title, 'action' => '续期', 'page' => '/pagesClient/official/index']]);
+                $notice = array_merge($notice, [['title' => $title, 'action' => '续期', 'page' => '/pagesClient/official/renewal']]);
             }
         }
 
@@ -100,4 +100,4 @@ class ConsoleController extends BaseController
         util::success(['dict' => $dict, 'shop' => $shop]);
     }
 
-}
+}

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

@@ -194,10 +194,10 @@ class OrderController extends BaseController
     public function actionOrderRelate()
     {
         $regionTree = RegionService::tree();
-        $shop = ShopService::getDefaultShop($this->sj);
+        $shop = $this->shop;
         $freight = MerchantExtendService::getFreight($this->sjExtend);
         $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
-        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->sj];
+        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
         util::success($out);
     }
 

+ 15 - 10
app-hd/controllers/PurchaseController.php

@@ -74,7 +74,7 @@ class PurchaseController extends BaseController
         $get = Yii::$app->request->get();
         $orderSn = $get['orderSn'] ?? 0;
         $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
-        PurchaseClass::valid($info->attributes, $this->shopId);
+        PurchaseService::valid($info, $this->shopId);
         $ghsId = $info->ghsId;
         $ghs = GhsClass::getGhsInfo($ghsId);
         $customId = $ghs['customId'] ?? 0;
@@ -88,7 +88,8 @@ class PurchaseController extends BaseController
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {
-            PurchaseClass::debt($info);
+            //延期支付
+            PurchaseService::debt($info);
             $transaction->commit();
         } catch (Exception $e) {
             $transaction->rollBack();
@@ -112,12 +113,12 @@ class PurchaseController extends BaseController
         if (empty($info)) {
             util::fail('没有找到采购单');
         }
-
-        PurchaseClass::valid($info->attributes, $this->shopId);
+        PurchaseService::valid($info, $this->shopId);
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {
-            purchaseClass::balancePay($info);
+            //余额支付
+            purchaseService::balancePay($info);
             $transaction->commit();
         } catch (Exception $e) {
             $transaction->rollBack();
@@ -135,8 +136,9 @@ class PurchaseController extends BaseController
         if (!empty($status)) {
             $where['status'] = $status;
         }
-        $list = PurchaseService::getPurchaseList($where);
-        util::success($list);
+        $respond = PurchaseService::getPurchaseList($where);
+        $respond['shop'] = $this->shop;
+        util::success($respond);
     }
 
     //采购详情 ssh 2021.01.25
@@ -144,8 +146,10 @@ class PurchaseController extends BaseController
     {
         $get = Yii::$app->request->get();
         $id = $get['id'] ?? 0;
-        $info = PurchaseClass::getInfo($id, true, true);
-        PurchaseClass::valid($info, $this->shopId);
+        $info = PurchaseService::getInfo($id, true, true);
+        if (isset($info['shopId']) == false || $info['shopId'] != $this->shopId) {
+            util::fail('没有权限访问');
+        }
         util::success($info);
     }
 
@@ -237,9 +241,10 @@ class PurchaseController extends BaseController
         util::success($newParams);
     }
 
-    //运费计算  linqh 2021.4.12  暂反回固定
+    //运费计算  linqh 2021.4.12  暂时返回固定值
     public function actionFreight()
     {
         util::success(['sedCost' => 10]);
     }
+
 }

+ 37 - 0
app-hd/controllers/ShopCouponController.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace hd\controllers;
+
+use biz\shop\services\ShopCouponService;
+use common\components\util;
+use Yii;
+
+class ShopCouponController extends BaseController
+{
+
+    public $guestAccess = [];
+
+    //门店列表 shish 2021.5.15
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['shopId'] = $this->shopId;
+        $status = $get['status'] ?? 0;
+        if (!empty($status)) {
+            $where['status'] = $status;
+        }
+        $list = ShopCouponService::getCouponList($where);
+        util::success($list);
+    }
+
+    //有可用红包 shish 2021.5.15
+    public function actionHas()
+    {
+        $data = [
+            'has' => rand(0, 1)
+        ];
+        util::success($data);
+    }
+
+}

+ 2 - 1
app-mall/controllers/OrderController.php

@@ -140,10 +140,11 @@ class OrderController extends BaseController
         $shop = $this->shop;
         $freight = ['first' => 5, 'add' => 2];
         $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
-        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->sj];
+        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
         util::success($out);
     }
 
+
     //余额支付 ssh 2019.12.6
     public function actionBalancePay()
     {

+ 2 - 2
biz-ghs/express/services/DadaExpressServices.php

@@ -37,9 +37,9 @@ class DadaExpressServices
         if (empty($orderInfo)) {
             util::fail("订单不存在");
         }
-        $sjId = $orderInfo['merchantId'];
+        $sjId = $orderInfo->merchantId;
         $sourceId = SjExpressClass::getSourceId($sjId);
-        $orderParams = self::orderParams($orderInfo);
+        $orderParams = self::orderParams($orderInfo->attributes);
         $res = dada::addOrder($sourceId, $orderParams);
         return $res;
     }

+ 56 - 147
biz-ghs/order/classes/OrderClass.php

@@ -14,6 +14,7 @@ use bizGhs\admin\classes\AdminClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\stat\classes\StatOrderCountClass;
 use bizGhs\stat\classes\StatYjClass;
+use bizHd\purchase\classes\PurchaseClass;
 use bizHd\stat\classes\StatIncomeClass;
 use bizHd\stat\classes\StatOrderClass;
 use common\components\dict;
@@ -118,8 +119,10 @@ class OrderClass extends BaseClass
         //将花店每月的总   订单数作为编号
         $data['sendNum'] = StatOrderCountClass::addOrder($month, $sjId);
         $data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
-        //订单30分钟后过期
-        $data['deadline'] = date("Y-m-d H:i:s", (time() + 1800));
+        //订单有效期
+        $validTime = dict::getDict('sale_purchase_order_valid');
+        $current = time() + $validTime;
+        $data['deadline'] = date("Y-m-d H:i:s", $current);
         $data['status'] = self::ORDER_STATUS_UN_PAY;
 
         //计算总重量(kg)
@@ -150,9 +153,9 @@ class OrderClass extends BaseClass
     }
 
     //根据订单编号查询 ssh 2021.19
-    public static function getByOrderSn($orderSn)
+    public static function getByOrderSn($orderSn, $returnObj = false)
     {
-        return self::getByCondition(['orderSn' => $orderSn]);
+        return self::getByCondition(['orderSn' => $orderSn], $returnObj);
     }
 
     //订单列表 ssh 2021.1.19
@@ -351,17 +354,6 @@ class OrderClass extends BaseClass
         util::fail('没有权限操作的订单');
     }
 
-    //获取订单详情 ssh 2021.1.21
-    public static function getOrderInfo($id, $showButton = false, $showItem = false, $showExpress = false, $isList = false)
-    {
-        $info = self::getById($id);
-        if (empty($info)) {
-            util::fail('没有找到订单');
-        }
-        $respond = self::groupOrder([$info], $showButton, $showItem, $showExpress, $isList);
-        return current($respond);
-    }
-
     //订单到期未付款未确认的订单置成取消状态 ssh 2021.1.23
     public static function setExpire($order)
     {
@@ -374,30 +366,32 @@ class OrderClass extends BaseClass
         }
     }
 
-    //确认送达 ssh 2021.3.4
-    public static function reach($order)
-    {
-        if ($order['status'] != OrderClass::ORDER_STATUS_SENDING) {
-            util::fail('订单没有在配送状态');
-        }
-        $id = $order['id'];
-        self::updateById($id, ['status' => self::ORDER_STATUS_COMPLETE, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
-        OrderSendClass::reach($order);
-    }
-
     //快递送 ssh 2021.3.16
     public static function thirdSend($order, $expressInfo)
     {
-        if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
+        if ($order->status == self::ORDER_STATUS_UN_PAY) {
             util::fail('订单未付款');
         }
-        if ($order['status'] != self::ORDER_STATUS_UN_SEND) {
+        if ($order->status != self::ORDER_STATUS_UN_SEND) {
             util::fail('不是待配送状态');
         }
-        $id = $order['id'];
+        $id = $order->id;
         $expressId = $expressInfo['expressId'] ?? 1;
         $expressName = $expressInfo['deliveryName'] ?? '达达';
-        self::updateById($id, ['status' => self::ORDER_STATUS_SENDING, 'sendType' => self::SEND_TYPE_THIRD, 'expressId' => $expressId]);
+
+        $order->status = self::ORDER_STATUS_SENDING;
+        $order->sendType = self::SEND_TYPE_THIRD;
+        $order->expressId = $expressId;
+        $order->save();
+
+        $shopId = $order->shopId;
+        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+        $shop->unSendOrder -= 1;
+        $shop->sendingOrder += 1;
+        $shop->save();
 
         $express = OrderExpressClass::getByCondition(['orderId' => $id]);
         if (!empty($express)) {
@@ -407,10 +401,8 @@ class OrderClass extends BaseClass
         //达达
         $dadaRes = DadaExpressServices::addOrder($order);
 
-
-        $orderSn = $order['orderSn'];
-        $sjId = $order['merchantId'] ?? 0;
-
+        $orderSn = $order->orderSn;
+        $sjId = $order->merchantId ?? 0;
 
         /*
         $getInfo = ExpressClass::getExpressInfo($expressId);
@@ -426,7 +418,7 @@ class OrderClass extends BaseClass
             'orderSn' => $orderSn,
             'sjId' => $sjId,
             'expressId' => $expressId,
-            'sendTime' => strtotime($order['sendTime']),
+            'sendTime' => strtotime($order->sendTime),
             'cost' => $dadaRes['fee'],
             'distance' => $dadaRes['distance'],
             'status' => 1,
@@ -442,38 +434,28 @@ class OrderClass extends BaseClass
             'status' => 2,
             'tip' => 0,
         ];
-        return $respond;
 
+        //采购单变成已发货
+        $purchaseId = $order->purchaseId ?? 0;
+        PurchaseClass::sending($purchaseId);
+
+        return $respond;
     }
 
     //本店送 ssh 2021.1.24
     public static function selfSend($info)
     {
-        if ($info['status'] == self::ORDER_STATUS_UN_PAY) {
+        if ($info->status == self::ORDER_STATUS_UN_PAY) {
             util::fail('订单未付款');
         }
-        if ($info['status'] != self::ORDER_STATUS_UN_SEND) {
+        if ($info->status != self::ORDER_STATUS_UN_SEND) {
             util::fail('不是待配送状态');
         }
-        $id = $info['id'];
-        self::updateById($id, ['status' => self::ORDER_STATUS_SENDING, 'sendType' => self::SEND_TYPE_MYSELF,]);
-        OrderSendClass::selfSend($info);
-    }
-
-    //自取和免发货流程的处理 ssh 2021.1.24
-    public static function withoutSend($order)
-    {
-        $id = $order->id ?? 0;
-        if (isset($order->status) == false) {
-            util::fail('没有订单状态');
-        }
-        if ($order->status == self::ORDER_STATUS_COMPLETE) {
-            util::fail('订单已完成');
-        }
+        $info->status = self::ORDER_STATUS_SENDING;
+        $info->sendType = self::SEND_TYPE_MYSELF;
+        $info->save();
 
-        //自取订单,订单直接完成。【现在有三个地方有订单完成操作】,找不到请搜索【】内关键词。
-        $currentOrder = self::getById($id, true);
-        $shopId = $order->shopId ?? 0;
+        $shopId = $info->shopId;
         $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
         if (empty($shop)) {
             util::fail('没有找到门店');
@@ -482,107 +464,24 @@ class OrderClass extends BaseClass
         $shop->sendingOrder += 1;
         $shop->save();
 
-        self::complete($currentOrder, $shop, self::TOTAL_FLOW, OrderClass::TOTAL_FLOW, self::SEND_TYPE_NO);
-
-        OrderSendClass::withoutSend($order);
-
-        return self::TOTAL_FLOW;
+        OrderSendClass::selfSend($info);
+        //采购单变成已发货
+        $purchaseId = $info->purchaseId ?? 0;
+        PurchaseClass::sending($purchaseId);
     }
 
     //订单完成 ssh 2020.3.12
-    public static function complete($order, $shop, $currentFlow, $totalFlow = false, $sendType = false)
+    public static function complete($order, $shop)
     {
         $order->status = OrderClass::ORDER_STATUS_COMPLETE;
-        $order->currentFlow = $currentFlow;
-        if (isset($totalFlow)) {
-            $order->totalFlow = $totalFlow;
-        }
-        if (isset($sendType)) {
-            $order->sendType = $sendType;
-        }
+        $order->currentFlow = self::TOTAL_FLOW;
+        $order->totalFlow = self::TOTAL_FLOW;
         $order->save();
 
         $shop->finishOrder += 1;
         $shop->sendingOrder -= 1;
         $shop->save();
-    }
-
-    public static function payAfter($order, $payWay)
-    {
-        if (isset($order->status) == false) {
-            util::fail('没有订单状态');
-        }
-        if ($order->status != self::ORDER_STATUS_UN_PAY) {
-            util::fail('重复操作');
-        }
-        if (isset($order->debt) == false) {
-            util::fail('订单有问题,没有欠款项');
-        }
-        /**门店资产变化**/
-        $amount = $order->actPrice ?? 0.00;
-        $currentShopId = $order->shopId ?? 0;
-        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $currentShopId])->one();
-        if (empty($shop)) {
-            util::fail('没有找到门店');
-        }
-        $shop->unPayOrder -= 1;
-        $shop->unSendOrder += 1;
-        $shop->totalOrderNum += 1;
-        $shop->totalIncome = bcadd($shop->totalIncome, $amount, 2);
-        $shop->save();
-
-        //更新订单基础状态和支付状态
-        $orderId = $order->id;
-        $orderSn = $order->orderSn;
-        $order->payWay = $payWay;
-        $order->status = self::ORDER_STATUS_UN_SEND;
-        if ($payWay == dict::getDict('payWay', 'debtPay')) {
-            $order->debt = self::DEBT_YES;
-        }
-        $order->save();
-
-        //员工业绩、总业绩增加
-        $shopAdminId = $order->shopAdminId ?? 0;
-        if (!empty($shopAdminId)) {
-            $shopAdmin = ShopAdminClass::getById($shopAdminId, true);
-            $shopAdmin->kdAmount = bcadd($shopAdmin->kdAmount, $amount, 2);
-            $shopAdmin->save();
-        }
-        StatYjClass::addYj($order);
-
-        /**客户资产变化**/
-        $customId = $order->customId;
-        $custom = Custom::findBySql('select * from ' . Custom::tableName() . ' where id = :id for update', ['id' => $customId])->one();
-        if (empty($custom)) {
-            util::fail('没有找到客户信息');
-        }
-        if ($payWay == dict::getDict('payWay', 'debtPay')) {
-            //欠款支付
-            $custom->isDebt = CustomClass::IS_DEBT_YES;
-            $custom->debtAmount = bcadd($custom->debtAmount, $amount, 2);
-            $custom->debtNum += 1;
-        }
-        $custom->buyNum += 1;
-        $custom->buyAmount = bcadd($custom->buyAmount, $amount, 2);
-        $custom->save();
-
-        //每天和每月收入
-        StatIncomeClass::updateOrInsert($shop, $order->actPrice);
-        //今日订单+1
-        StatOrderClass::updateOrInsert($shop);
-
-        //显示已下单流程
-        $time = date("Y-m-d H:i:s");
-        $placeData = ['payTime' => $time, 'orderSn' => $orderSn, 'orderId' => $orderId];
-        OrderSendClass::placeOrder($placeData);
-
-        //自取订单,订单直接完成,【现在有三个地方有订单完成操作】,找不到请搜索【】内关键词。
-        if (isset($order->sendType) == false) {
-            util::fail('没有找到配送方式');
-        }
-        if ($order->sendType == OrderClass::SEND_TYPE_NO) {
-            self::withoutSend($order);
-        }
+        return $order;
     }
 
     //修改订单表的配送信息 linqh 2021.3.28
@@ -617,6 +516,16 @@ class OrderClass extends BaseClass
         }
         $order->status = self::ORDER_STATUS_CANCEL;
         $order->save();
+
+        $shopId = $order->shopId;
+        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+        $shop->unPayOrder -= 1;
+        $shop->cancelOrder += 1;
+        $shop->save();
+
         return $order;
     }
 

+ 12 - 21
biz-ghs/order/classes/OrderExpressClass.php

@@ -16,11 +16,12 @@ class OrderExpressClass extends BaseClass
     public static $baseFile = '\bizGhs\order\models\OrderExpress';
 
     public static $statusMap = [
-        self::STATUS_INIT=>'待接单',
-        self::STATUS_RECEIVE=>'已接单',
-        self::STATUS_COMPLETE=>'已完成',
-        self::STATUS_CANCEL=>'取消',
+        self::STATUS_INIT => '待接单',
+        self::STATUS_RECEIVE => '已接单',
+        self::STATUS_COMPLETE => '已完成',
+        self::STATUS_CANCEL => '取消',
     ];
+
     //获取配送进展
     public static function getProgress($showExpress, $order)
     {
@@ -32,7 +33,7 @@ class OrderExpressClass extends BaseClass
         }
         $res = DadaExpressServices::statusOrder($order['orderSn']);
         return [
-            'progressName' => $res['statusMsg']??'',
+            'progressName' => $res['statusMsg'] ?? '',
         ];
     }
 
@@ -53,26 +54,16 @@ class OrderExpressClass extends BaseClass
     }
 
     //已取货
-    public static function pickUp($order,$dmName,$dmMobile)
-    {
-        $orderSn = $order['orderSn'];
-        $data = [
-            'dmName'=>$dmName,
-            'dmMobile'=>$dmMobile,
-        ];
-        return self::updateByCondition(['orderSn'=>$orderSn],$data);
-    }
-
-    //配送完成
-    public static function reach($order)
+    public static function pickUp($order, $dmName, $dmMobile)
     {
-        self::updateExpressStatus($order['orderSn'],OrderExpressClass::STATUS_COMPLETE);
-        return true;
+        $order->dmName = $dmName;
+        $order->dmMobile = $dmMobile;
+        return $order->save();
     }
 
     //修改快递状态
-    public static function updateExpressStatus($orderSn,$status)
+    public static function updateExpressStatus($orderSn, $status)
     {
-        return self::updateByCondition(['orderSn'=>$orderSn],['status'=>$status]);
+        return self::updateByCondition(['orderSn' => $orderSn], ['status' => $status]);
     }
 }

+ 2 - 2
biz-ghs/order/classes/OrderSendClass.php

@@ -20,7 +20,7 @@ class OrderSendClass extends BaseClass
 
     public static function thirdSend($order)
     {
-        $orderSn = $order['orderSn'];
+        $orderSn = $order->orderSn;
         $relation = self::ACTION_RELATION;
         $currentId = $relation['deliver'] ?? 0;
         if (empty($currentId)) {
@@ -40,7 +40,7 @@ class OrderSendClass extends BaseClass
     //本店送 ssh 2021.3.4
     public static function selfSend($order)
     {
-        $orderSn = $order['orderSn'];
+        $orderSn = $order->orderSn;
         $relation = self::ACTION_RELATION;
         $currentId = $relation['deliver'] ?? 0;
         if (empty($currentId)) {

+ 122 - 122
biz-ghs/order/services/OrderSendService.php

@@ -13,128 +13,128 @@ class OrderSendService extends BaseService
 {
 
     public static $baseFile = '\bizGhs\order\classes\OrderSendClass';
-
-
-    //制单 ssh 2019.12.17
-    public static function printOrder($data)
-    {
-        $id = $data['id'];
-        $orderSn = $data['orderSn'];
-        $option = $data['option'];
-        $actionRelation = OrderSendClass::ACTION_RELATION;
-        $printOrderId = $actionRelation['printOrder'];
-        $currentId = OrderSendClass::toDoActionId($orderSn);
-        if ($printOrderId != $currentId) {
-            util::fail('当前流程无法操作');
-        }
-        //1有配送单 2 填单制单
-        if (in_array($option, [1, 2]) == false) {
-            util::fail('操作无效');
-        }
-        $time = time();
-        OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $printOrderId], ['option' => $option, 'finishTime' => $time]);
-        $hasDeliver = 0;
-        if ($option == 1) {
-            //有纸质配送单
-            $hasDeliver = 1;
-        }
-        if ($option == 2) {
-            //填单制单
-            $hasDeliver = 2;
-        }
-        OrderClass::updateById($id, ['status' => OrderClass::ORDER_STATUS_UN_SEND, 'currentFlow' => 2, 'printStatus' => 1, 'hasDeliver' => $hasDeliver]);
-
-        //显示发货流程
-        $deliverId = $actionRelation['deliver'];
-        $data = ['actionId' => $deliverId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $deliverId, 'orderSn' => $orderSn];
-        OrderSendClass::add($data);
-        $actionList = OrderSendClass::ACTION_LIST;
-        $data['actionSign'] = isset($actionList[$deliverId]['sign']) ? $actionList[$deliverId]['sign'] : '';
-        util::success(['nextAction' => $data]);
-    }
-
-    //发货 ssh 2019.12.17
-    public static function deliver($data)
-    {
-        $id = $data['id'];
-        $orderSn = $data['orderSn'];
-        $option = $data['option'];
-        $actionRelation = OrderSendClass::ACTION_RELATION;
-        $deliverId = $actionRelation['deliver'];
-        $currentId = OrderSendClass::toDoActionId($orderSn);
-        if ($deliverId != $currentId) {
-            util::fail('当前流程无法操作');
-        }
-        $time = time();
-        $sendType = isset($data['sendType']) ? $data['sendType'] : OrderClass::SEND_TYPE_UNKNOWN;
-        $sendInfo = [];
-        if ($sendType == OrderClass::SEND_TYPE_THIRD) {
-            util::fail('即将开通...');
-            $side = $data['expressId'];
-            $sendTime = strtotime(date("Y-m-d") . ' ' . $data['sendTime']);
-            if ($sendTime < ($time + 20 * 60)) {
-                util::fail('请选择20分钟之后的时间');
-            }
-            $sendInfo = [
-                'sideId' => $side,
-                'sendTime' => $sendTime,
-                'addTime' => $time,
-                'sendTip' => 0,
-                'merchantId' => $data['merchantId'],
-                'orderId' => $id,
-                'cost' => 6,
-                'tip' => 0,
-                'distance' => 7,
-                'sendTime' => $sendTime,
-                'side' => $side,
-            ];
-            OrderExpressClass::add($sendInfo);
-        }
-
-        OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $deliverId], ['option' => $option, 'finishTime' => $time]);
-        OrderClass::updateById($id, ['status' => OrderClass::ORDER_STATUS_SENDING, 'currentFlow' => 3, 'sendType' => $sendType]);
-
-        //待发货订单-1,配送中订单+1
-        $shopId = $data['shopId'];
-        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
-        if (empty($shop)) {
-            util::fail('没有找到门店');
-        }
-        $shop->unSendOrder -= 1;
-        $shop->sendingOrder += 1;
-        $shop->save();
-
-        //显示送达流程
-        $reachId = $actionRelation['reach'];
-        $data = ['actionId' => $reachId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $reachId, 'orderSn' => $orderSn];
-        OrderSendClass::add($data);
-        $actionList = OrderSendClass::ACTION_LIST;
-        $data['actionSign'] = isset($actionList[$reachId]['sign']) ? $actionList[$reachId]['sign'] : '';
-        util::success(['nextAction' => $data, 'sendInfo' => $sendInfo]);
-    }
-
-    //送达 ssh 2019.12.17
-    public static function reach($order)
-    {
-        $orderSn = $order['orderSn'];
-        $actionRelation = OrderSendClass::ACTION_RELATION;
-        $reachId = $actionRelation['reach'];
-        $currentId = OrderSendClass::toDoActionId($orderSn);
-        if ($reachId != $currentId) {
-            util::fail('当前流程无法操作');
-        }
-        OrderSendClass::reach($order);
-
-        //送达,订单完成。【现在有三个地方有订单完成操作】,找不到请搜索【】内关键词。
-        $id = $order['id'];
-        $currentOrder = self::getById($id, true);
-        $shopId = $order['shopId'] ?? 0;
-        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
-        if (empty($shop)) {
-            util::fail('没有找到门店');
-        }
-        OrderClass::complete($currentOrder, $shop, OrderClass::TOTAL_FLOW);
-    }
+//
+//
+//    //制单 ssh 2019.12.17
+//    public static function printOrder($data)
+//    {
+//        $id = $data['id'];
+//        $orderSn = $data['orderSn'];
+//        $option = $data['option'];
+//        $actionRelation = OrderSendClass::ACTION_RELATION;
+//        $printOrderId = $actionRelation['printOrder'];
+//        $currentId = OrderSendClass::toDoActionId($orderSn);
+//        if ($printOrderId != $currentId) {
+//            util::fail('当前流程无法操作');
+//        }
+//        //1有配送单 2 填单制单
+//        if (in_array($option, [1, 2]) == false) {
+//            util::fail('操作无效');
+//        }
+//        $time = time();
+//        OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $printOrderId], ['option' => $option, 'finishTime' => $time]);
+//        $hasDeliver = 0;
+//        if ($option == 1) {
+//            //有纸质配送单
+//            $hasDeliver = 1;
+//        }
+//        if ($option == 2) {
+//            //填单制单
+//            $hasDeliver = 2;
+//        }
+//        OrderClass::updateById($id, ['status' => OrderClass::ORDER_STATUS_UN_SEND, 'currentFlow' => 2, 'printStatus' => 1, 'hasDeliver' => $hasDeliver]);
+//
+//        //显示发货流程
+//        $deliverId = $actionRelation['deliver'];
+//        $data = ['actionId' => $deliverId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $deliverId, 'orderSn' => $orderSn];
+//        OrderSendClass::add($data);
+//        $actionList = OrderSendClass::ACTION_LIST;
+//        $data['actionSign'] = isset($actionList[$deliverId]['sign']) ? $actionList[$deliverId]['sign'] : '';
+//        util::success(['nextAction' => $data]);
+//    }
+//
+//    //发货 ssh 2019.12.17
+//    public static function deliver($data)
+//    {
+//        $id = $data['id'];
+//        $orderSn = $data['orderSn'];
+//        $option = $data['option'];
+//        $actionRelation = OrderSendClass::ACTION_RELATION;
+//        $deliverId = $actionRelation['deliver'];
+//        $currentId = OrderSendClass::toDoActionId($orderSn);
+//        if ($deliverId != $currentId) {
+//            util::fail('当前流程无法操作');
+//        }
+//        $time = time();
+//        $sendType = isset($data['sendType']) ? $data['sendType'] : OrderClass::SEND_TYPE_UNKNOWN;
+//        $sendInfo = [];
+//        if ($sendType == OrderClass::SEND_TYPE_THIRD) {
+//            util::fail('即将开通...');
+//            $side = $data['expressId'];
+//            $sendTime = strtotime(date("Y-m-d") . ' ' . $data['sendTime']);
+//            if ($sendTime < ($time + 20 * 60)) {
+//                util::fail('请选择20分钟之后的时间');
+//            }
+//            $sendInfo = [
+//                'sideId' => $side,
+//                'sendTime' => $sendTime,
+//                'addTime' => $time,
+//                'sendTip' => 0,
+//                'merchantId' => $data['merchantId'],
+//                'orderId' => $id,
+//                'cost' => 6,
+//                'tip' => 0,
+//                'distance' => 7,
+//                'sendTime' => $sendTime,
+//                'side' => $side,
+//            ];
+//            OrderExpressClass::add($sendInfo);
+//        }
+//
+//        OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $deliverId], ['option' => $option, 'finishTime' => $time]);
+//        OrderClass::updateById($id, ['status' => OrderClass::ORDER_STATUS_SENDING, 'currentFlow' => 3, 'sendType' => $sendType]);
+//
+//        //待发货订单-1,配送中订单+1
+//        $shopId = $data['shopId'];
+//        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+//        if (empty($shop)) {
+//            util::fail('没有找到门店');
+//        }
+//        $shop->unSendOrder -= 1;
+//        $shop->sendingOrder += 1;
+//        $shop->save();
+//
+//        //显示送达流程
+//        $reachId = $actionRelation['reach'];
+//        $data = ['actionId' => $reachId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $reachId, 'orderSn' => $orderSn];
+//        OrderSendClass::add($data);
+//        $actionList = OrderSendClass::ACTION_LIST;
+//        $data['actionSign'] = isset($actionList[$reachId]['sign']) ? $actionList[$reachId]['sign'] : '';
+//        util::success(['nextAction' => $data, 'sendInfo' => $sendInfo]);
+//    }
+//
+//    //送达 ssh 2019.12.17
+//    public static function reach($order)
+//    {
+//        $orderSn = $order['orderSn'];
+//        $actionRelation = OrderSendClass::ACTION_RELATION;
+//        $reachId = $actionRelation['reach'];
+//        $currentId = OrderSendClass::toDoActionId($orderSn);
+//        if ($reachId != $currentId) {
+//            util::fail('当前流程无法操作');
+//        }
+//        OrderSendClass::reach($order);
+//
+//        //送达,订单完成。【现在有三个地方有订单完成操作】
+//        $id = $order['id'];
+//        $currentOrder = self::getById($id, true);
+//        $shopId = $order['shopId'] ?? 0;
+//        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+//        if (empty($shop)) {
+//            util::fail('没有找到门店');
+//        }
+//        OrderClass::complete($currentOrder, $shop, OrderClass::TOTAL_FLOW);
+//    }
 
     //发货详情 ssh 2019.12.15
     public static function sendList($order)

+ 186 - 8
biz-ghs/order/services/OrderService.php

@@ -3,9 +3,18 @@
 namespace bizGhs\order\services;
 
 use biz\ghs\classes\GhsClass;
+use biz\shop\classes\ShopAdminClass;
 use biz\shop\models\Shop;
 use bizGhs\base\services\BaseService;
+use bizGhs\custom\classes\CustomClass;
+use bizGhs\custom\models\Custom;
 use bizGhs\order\classes\OrderClass;
+use bizGhs\order\classes\OrderExpressClass;
+use bizGhs\order\classes\OrderSendClass;
+use bizGhs\stat\classes\StatYjClass;
+use bizHd\purchase\services\PurchaseService;
+use bizHd\stat\classes\StatIncomeClass;
+use bizHd\stat\classes\StatOrderClass;
 use common\components\dict;
 use common\components\util;
 use bizHd\purchase\classes\PurchaseClass;
@@ -64,17 +73,96 @@ class OrderService extends BaseService
 
         $return->purchaseId = $purchaseId;
         $return->save();
-        OrderClass::payAfter($return);
-        PurchaseClass::payAfter($purchase);
+        self::payAfter($return, $payWay);
+        PurchaseService::payAfter($purchase, $payWay);
 
+        if (isset($return->sendType) == false) {
+            util::fail('没有找到配送方式');
+        }
         //自取订单直接完成
-        if (isset($data['sendType']) && $data['sendType'] == OrderClass::SEND_TYPE_NO) {
-            OrderClass::withoutSend($return);
+        if ($return->sendType == OrderClass::SEND_TYPE_NO) {
+            self::withoutSend($return, $purchase);
         }
 
         return $return->attributes;
     }
 
+    //自取免配送流程处理 ssh 2021.1.24
+    public static function withoutSend($order, $purchase)
+    {
+        if (isset($order->status) == false) {
+            util::fail('没有订单状态');
+        }
+        if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
+            util::fail('订单已完成');
+        }
+        //自取订单,订单直接完成。【现在有三个地方有订单完成操作】
+        $shopId = $order->shopId ?? 0;
+        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+        $shop->unSendOrder -= 1;
+        $shop->sendingOrder += 1;
+        $shop->save();
+        //自取免配送
+        $order->sendType = OrderClass::SEND_TYPE_NO;
+        $order->save();
+
+        //订单完成
+        self::finish($order, $shop);
+
+        $purchaseShopId = $purchase->shopId;
+        $purchaseShop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $purchaseShopId])->one();
+        if (empty($purchaseShop)) {
+            util::fail('没有找到门店');
+        }
+        $purchaseShop->cgUnSend -= 1;
+        $purchaseShop->cgSending += 1;
+        $purchaseShop->save();
+
+        OrderSendClass::withoutSend($order);
+
+        return OrderClass::TOTAL_FLOW;
+    }
+
+    //确认送达 ssh 2021.3.4
+    public static function reach($order)
+    {
+        if ($order->status != OrderClass::ORDER_STATUS_SENDING) {
+            util::fail('订单没有在配送状态');
+        }
+        //第三方配送的变更第三方订单状态
+        if (isset($order->sendType) && $order->sendType == OrderClass::SEND_TYPE_THIRD) {
+            $express = OrderExpressClass::getByCondition(['orderSn' => $order->orderSn], true);
+            if (!empty($express)) {
+                $express->status = OrderExpressClass::STATUS_COMPLETE;
+                $express->save();
+            }
+        }
+        $shopId = $order->shopId ?? 0;
+        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+
+        //订单完成
+        self::finish($order, $shop);
+
+        OrderSendClass::reach($order);
+    }
+
+    //订单完成
+    public static function finish($order, $shop)
+    {
+        //销售单完成
+        $order = OrderClass::complete($order, $shop);
+        //采购单完成
+        $purchaseId = $order->purchaseId ?? 0;
+        $purchase = PurchaseClass::getById($purchaseId, true);
+        PurchaseClass::complete($purchase);
+    }
+
     //获取订单信息 ssh 2019.11.28
     public static function getOrderList($where)
     {
@@ -290,12 +378,102 @@ class OrderService extends BaseService
         return ['price' => $discountPrice, 'discountType' => $discountType, 'discountAmount' => $discountAmount];
     }
 
+    //获取订单详情 ssh 2021.1.21
+    public static function getOrderInfo($id, $showButton = false, $showItem = false, $showExpress = false, $isList = false)
+    {
+        $order = OrderClass::getById($id, true);
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        $order = self::expire($order);
+        $info = $order->attributes;
+        $respond = OrderClass::groupOrder([$info], $showButton, $showItem, $showExpress, $isList);
+        return current($respond);
+    }
+
     //订单失效后的操作 shish 2021.5.14
-    public static function expire($id)
+    public static function expire($order)
     {
-        $order = OrderClass::cancel($id);
-        $purchaseId = $order->purchaseId;
-        PurchaseClass::cancel($purchaseId);
+        $date = date("Y-m-d H:i:s");
+        if ($order->status == OrderClass::ORDER_STATUS_UN_PAY && $order->deadline <= $date) {
+            $id = $order->id;
+            $order = OrderClass::cancel($id);
+            $purchaseId = $order->purchaseId;
+            PurchaseClass::cancel($purchaseId);
+            return $order;
+        }
+        return $order;
+    }
+
+    //支付成功后的流程 shish 2021.5.14
+    public static function payAfter($order, $payWay)
+    {
+        if (isset($order->status) == false) {
+            util::fail('没有订单状态');
+        }
+        if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
+            util::fail('重复操作');
+        }
+        if (isset($order->debt) == false) {
+            util::fail('订单有问题,没有欠款项');
+        }
+        /**门店资产变化**/
+        $amount = $order->actPrice ?? 0.00;
+        $currentShopId = $order->shopId ?? 0;
+        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $currentShopId])->one();
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+        $shop->unPayOrder -= 1;
+        $shop->unSendOrder += 1;
+        $shop->totalOrderNum += 1;
+        $shop->totalIncome = bcadd($shop->totalIncome, $amount, 2);
+        $shop->save();
+
+        //更新订单基础状态和支付状态
+        $orderId = $order->id;
+        $orderSn = $order->orderSn;
+        $order->payWay = $payWay;
+        $order->status = OrderClass::ORDER_STATUS_UN_SEND;
+        if ($payWay == dict::getDict('payWay', 'debtPay')) {
+            $order->debt = OrderClass::DEBT_YES;
+        }
+        $order->save();
+
+        //员工业绩、总业绩增加
+        $shopAdminId = $order->shopAdminId ?? 0;
+        if (!empty($shopAdminId)) {
+            $shopAdmin = ShopAdminClass::getById($shopAdminId, true);
+            $shopAdmin->kdAmount = bcadd($shopAdmin->kdAmount, $amount, 2);
+            $shopAdmin->save();
+        }
+        StatYjClass::addYj($order);
+
+        /**客户资产变化**/
+        $customId = $order->customId;
+        $custom = Custom::findBySql('select * from ' . Custom::tableName() . ' where id = :id for update', ['id' => $customId])->one();
+        if (empty($custom)) {
+            util::fail('没有找到客户信息');
+        }
+        if ($payWay == dict::getDict('payWay', 'debtPay')) {
+            //欠款支付
+            $custom->isDebt = CustomClass::IS_DEBT_YES;
+            $custom->debtAmount = bcadd($custom->debtAmount, $amount, 2);
+            $custom->debtNum += 1;
+        }
+        $custom->buyNum += 1;
+        $custom->buyAmount = bcadd($custom->buyAmount, $amount, 2);
+        $custom->save();
+
+        //每天和每月收入
+        StatIncomeClass::updateOrInsert($shop, $order->actPrice);
+        //今日订单+1
+        StatOrderClass::updateOrInsert($shop);
+
+        //显示已下单流程
+        $time = date("Y-m-d H:i:s");
+        $placeData = ['payTime' => $time, 'orderSn' => $orderSn, 'orderId' => $orderId];
+        OrderSendClass::placeOrder($placeData);
     }
 
 }

+ 5 - 1
biz-ghs/ws/services/WsService.php

@@ -5,7 +5,7 @@ namespace bizGhs\ws\services;
 use GatewayClient\Gateway;
 class WsService
 {
-    //到账通知
+    //到账通知 $adminId 为 shopAdminId
     public static function arrivalNotice($adminId,$money,$payWay='')
     {
         $msg = '到账'.$money;
@@ -13,4 +13,8 @@ class WsService
         Gateway::sendToUid($adminId, json_encode($data));
         return true;
     }
+
+    //零售端采购时,提示供货商(下所有有开启通知的员工),你有新订单
+    //商城客户下单时,提示零售花店(下所有有开启通知的员工) 你有新的订单
+    //todo
 }

+ 66 - 144
biz-hd/purchase/classes/PurchaseClass.php

@@ -3,16 +3,10 @@
 namespace bizHd\purchase\classes;
 
 use biz\ghs\classes\GhsClass;
-use biz\ghs\models\Ghs;
 use biz\shop\models\Shop;
 use bizGhs\admin\classes\AdminClass;
-use bizGhs\custom\classes\CustomClass;
-use bizGhs\custom\models\Custom;
-use bizGhs\order\classes\OrderSendClass;
-use bizGhs\order\models\Order;
 use bizGhs\order\traits\OrderTrait;
 use bizGhs\product\classes\ProductClass;
-use bizGhs\order\classes\OrderClass;
 use bizHd\purchase\models\Purchase;
 use common\components\dict;
 use common\components\orderSn;
@@ -68,9 +62,9 @@ class PurchaseClass extends BaseClass
         //传过滤的productId 是供货商的,需要转换为零售端(hd)的productId
         //补充了hdProductId
         //[{"productId":"113","bigNum":1,"smallNum":0,"classId":"-2","hdProductId":1}]
-        $hdShopId = $data['shopId'] ?? 0;
-        $hdSjId = $data['merchantId'] ?? 0;
-        $productList = ProductClass::toggleProductList($productList, $hdShopId, $hdSjId);
+        $shopId = $data['shopId'] ?? 0;
+        $sjId = $data['merchantId'] ?? 0;
+        $productList = ProductClass::toggleProductList($productList, $shopId, $sjId);
 
         $productData = self::getProductMapData($productList, "productId");
         $hdProductData = self::getProductMapData($productList, "hdProductId");
@@ -131,26 +125,28 @@ class PurchaseClass extends BaseClass
         $data['actPrice'] = $actPrice;
         $data['bigNum'] = $bigNum;
         $data['smallNum'] = $smallNum;
-        //采购单5分钟有效期
-        $current = time() + 300;
+        //采购单有效期
+        $validTime = dict::getDict('sale_purchase_order_valid');
+        $current = time() + $validTime;
         $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current);
         $respond = self::add($data, true);
         if (isset($data['product']) == false || empty($data['product'])) {
             util::fail('请选择花材');
         }
         PurchaseItemClass::batchAdd($productList);
-        return $respond;
-    }
 
-    //获取采购单信息 ssh 2021.1.24
-    public static function getInfo($id, $showButton = false, $showProduct = false)
-    {
-        $info = self::getById($id);
-        $respond = self::groupPurchase([$info], $showButton, $showProduct);
-        return current($respond);
+        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+        $shop->totalPurchaseOrder += 1;
+        $shop->cgUnPay += 1;
+        $shop->save();
 
+        return $respond;
     }
 
+
     //组合数据 ssh 2021.1.25
     public static function groupPurchase($list, $showButton = false, $showProduct = false)
     {
@@ -205,140 +201,23 @@ class PurchaseClass extends BaseClass
         return $list;
     }
 
-    //订单延期支付 ssh 2021.1.24
-    public static function debt($info)
-    {
-        $payWay = dict::getDict('payWay', 'debtPay');
-        self::payAfter($info, $payWay);
-
-        $saleId = $info->saleId ?? 0;
-        $order = OrderClass::getById($saleId, true);
-        OrderClass::payAfter($order, $payWay);
-    }
-
-    //余额支付 ssh 2021.1.24
-    public static function balancePay($info)
-    {
-        $payWay = dict::getDict('payWay', 'balancePay');
-        self::payAfter($info, $payWay);
-
-        $saleId = $info->saleId ?? 0;
-        $order = OrderClass::getById($saleId, true);
-        OrderClass::payAfter($order, $payWay);
-    }
-
-    //检查采购单
-    public static function valid($info, $shopId)
-    {
-        if (empty($info)) {
-            util::fail('没有找到采购单');
-        }
-        if (isset($info['shopId']) && $info['shopId'] == $shopId) {
-            return true;
-        }
-        util::fail('没有权限操作');
-    }
-
-
-    //采购订单支付成功后回调处理流程
-    public static function thirdPay($payWay, $orderSn, $totalFee, $attach)
-    {
-        $info = self::getByCondition(['orderSn' => $orderSn], true);
-        if (empty($info)) {
-            $msg = "没有找到订单 orderSn:{$orderSn}";
-            Yii::info($msg);
-            util::fail($msg);
-        }
-        if ($info->actPrice != $totalFee) {
-            $msg = "订单金额与回调通知金额不一致 orderSn:{$orderSn} {$info->actPrice} {$totalFee}";
-            Yii::info($msg);
-            util::fail($msg);
-        }
-        self::payAfter($info, $payWay);
-
-        $saleId = $info->saleId ?? 0;
-        $order = OrderClass::getById($saleId, true);
-        OrderClass::payAfter($order, $payWay);
-    }
 
-    //第三方支付、余额支付和欠款支付后调用的流程 shish 2021.4.27
-    public static function payAfter($info, $payWay)
+    //订单取消,变更状态,占用库存释放 shish 2021.5.8
+    public static function cancel($id)
     {
-        if (empty($info)) {
-            util::fail('没有找到订单');
-        }
-        $deadline = $info->deadline;
-        if ($deadline <= date("Y-m-d H:i:s")) {
-            self::cancel($info->id);
-            util::fail('订单已失效,请重新采购');
-        }
-        if (isset($info->status) == false || $info->status != self::STATUS_UN_PAY) {
-            util::fail('订单不是待付款状态');
-        }
-
-        /**零售采购单状态变化**/
-        $info->payWay = $payWay;
-        $info->status = self::STATUS_UN_SEND;
-        if ($payWay == dict::getDict('payWay', 'debtPay')) {
-            //欠款支付
-            $info->debt = 1;
-        }
-        $info->save();
+        $purchase = Purchase::findBySql('select * from ' . Purchase::tableName() . ' where id = :id for update', ['id' => $id])->one();
+        $purchase->status = self::STATUS_CANCEL;
+        $purchase->save();
 
-        /**零售门店资产变化**/
-        $shopId = $info['shopId'] ?? 0;
+        $shopId = $purchase->shopId;
         $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
         if (empty($shop)) {
             util::fail('没有找到门店');
         }
-        $actPrice = $info->actPrice;
-        if ($payWay == dict::getDict('payWay', 'balancePay')) {
-            if (bccomp($actPrice, $shop->balance, 2) == 1) {
-                util::fail('余额不足');
-            }
-            $shop->balance = bcsub($shop->balance, $actPrice, 2);
-        }
-        $shop->totalPurchase = bcadd($shop->totalPurchase, $actPrice, 2);
-        $shop->totalPurchaseOrder += 1;
+        $shop->cgUnPay -= 1;
+        $shop->cgCancel += 1;
         $shop->save();
 
-        /**零售的供货商资产变化**/
-        $ghsId = $info->ghsId ?? 0;
-        $ghs = Ghs::findBySql('select * from ' . Ghs::tableName() . ' where id = :id for update', ['id' => $ghsId])->one();
-        if (empty($ghs)) {
-            util::fail('没有找到供货商');
-        }
-        if ($payWay == dict::getDict('payWay', 'debtPay')) {
-            //欠款支付
-            $ghs->debt = 2;
-            $ghs->debtAmount = bcadd($ghs->debtAmount, $actPrice, 2);
-            $ghs->debtNum += 1;
-        }
-        $ghs->expendAmount = bcadd($ghs->expendAmount, $actPrice, 2);
-        $ghs->expendNum += 1;
-        $ghs->save();
-
-        /********订单完成后加库存 linqh 2021-05-10*********/
-        $orderSn = $info->orderSn;
-        $purchaseItem = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, "*");
-        foreach ($purchaseItem as $v) {
-            ProductClass::addStockByItemNum($v['productId'], $v['itemNum']);
-        }
-
-    }
-
-    //订单取消,变更状态,占用库存释放 shish 2021.5.8
-    public static function cancel($id)
-    {
-        $purchase = Purchase::findBySql('select * from ' . Purchase::tableName() . ' where id = :id for update', ['id' => $id])->one();
-        $purchase->status = self::STATUS_CANCEL;
-        $purchase->save();
-        //供货商那边加回库存
-        $orderSn = $purchase->orderSn;
-        $purchaseItem = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, "*");
-        foreach ($purchaseItem as $v) {
-            ProductClass::addStockByItemNum($v['ghsProductId'], $v['itemNum']);
-        }
         return $purchase;
     }
 
@@ -384,4 +263,47 @@ class PurchaseClass extends BaseClass
 
     }
 
+    //采购单完成 shish 2021.5.15
+    public static function complete($purchase)
+    {
+        $purchase->status = self::STATUS_COMPLETE;
+        $purchase->save();
+
+        $shopId = $purchase->shopId;
+        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+        $shop->cgSending -= 1;
+        $shop->cgFinish += 1;
+        $shop->save();
+
+        /********订单完成后加库存 linqh 2021-05-10*********/
+        $orderSn = $purchase->orderSn;
+        $purchaseItem = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, "*");
+        foreach ($purchaseItem as $v) {
+            ProductClass::addStockByItemNum($v['productId'], $v['itemNum']);
+        }
+    }
+
+    //订单信息变更为配送中 shish 2021.5.15
+    public static function sending($purchaseId)
+    {
+        $purchase = PurchaseClass::getById($purchaseId, true);
+        if (empty($purchase)) {
+            util::fail('没有采购单信息');
+        }
+        $purchase->status = PurchaseClass::STATUS_SENDING;
+        $purchase->save();
+
+        $shopId = $purchase->shopId;
+        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+        $shop->cgUnSend -= 1;
+        $shop->cgSending += 1;
+        $shop->save();
+    }
+
 }

+ 143 - 9
biz-hd/purchase/services/PurchaseService.php

@@ -2,12 +2,14 @@
 
 namespace bizHd\purchase\services;
 
-use biz\ghs\classes\GhsClass;
+use biz\ghs\models\Ghs;
+use biz\shop\models\Shop;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\order\classes\OrderClass;
+use bizGhs\order\services\OrderService;
 use bizHd\base\services\BaseService;
 use bizHd\purchase\classes\PurchaseClass;
-use bizGhs\admin\classes\AdminClass;
+use common\components\dict;
 use common\components\imgUtil;
 use common\components\util;
 use Yii;
@@ -70,11 +72,37 @@ class PurchaseService extends BaseService
         ];
         $result = OrderClass::addOrder($arr);
         $saleId = $result['id'] ?? 0;
-        PurchaseClass::updateById($purchaseId, ['saleId' => $saleId]);
+        $respond->saleId = $saleId;
+        $respond->save();
 
         return $respond;
     }
 
+    //获取采购单信息 ssh 2021.1.24
+    public static function getInfo($id, $showButton = false, $showProduct = false)
+    {
+        $purchase = PurchaseClass::getById($id, true);
+        if (empty($purchase)) {
+            util::fail('没有找到采购单');
+        }
+        $purchase = self::expire($purchase);
+        $info = $purchase->attributes;
+        $respond = PurchaseClass::groupPurchase([$info], $showButton, $showProduct);
+        return current($respond);
+    }
+
+    //检查采购单
+    public static function valid($info, $shopId)
+    {
+        if (empty($info)) {
+            util::fail('没有找到采购单');
+        }
+        if (isset($info->shopId) && $info->shopId == $shopId) {
+            return true;
+        }
+        util::fail('没有权限操作');
+    }
+
     //采购记录 ssh 2021.1.24
     public static function getPurchaseList($where)
     {
@@ -104,13 +132,119 @@ class PurchaseService extends BaseService
     }
 
     //采购单失效 shish 2021.5.14
-    public static function expire($id)
+    public static function expire($purchase)
+    {
+        $date = date("Y-m-d H:i:s");
+        if ($purchase->status == PurchaseClass::STATUS_UN_PAY && $purchase->deadline <= $date) {
+            //采购单失效
+            $id = $purchase->id;
+            $purchase = PurchaseClass::cancel($id);
+            $saleId = $purchase->saleId;
+            //销售单失效
+            OrderClass::cancel($saleId);
+        }
+        return $purchase;
+    }
+
+    //订单延期支付 ssh 2021.1.24
+    public static function debt($info)
+    {
+        $payWay = dict::getDict('payWay', 'debtPay');
+        self::payAfter($info, $payWay);
+
+        $saleId = $info->saleId ?? 0;
+        $order = OrderClass::getById($saleId, true);
+        OrderService::payAfter($order, $payWay);
+    }
+
+    //余额支付 ssh 2021.1.24
+    public static function balancePay($info)
+    {
+        $payWay = dict::getDict('payWay', 'balancePay');
+        self::payAfter($info, $payWay);
+
+        $saleId = $info->saleId ?? 0;
+        $order = OrderClass::getById($saleId, true);
+        OrderService::payAfter($order, $payWay);
+    }
+
+    //采购订单支付成功后回调处理流程
+    public static function thirdPay($payWay, $orderSn, $totalFee, $attach)
+    {
+        $info = self::getByCondition(['orderSn' => $orderSn], true);
+        if (empty($info)) {
+            $msg = "没有找到订单 orderSn:{$orderSn}";
+            Yii::info($msg);
+            util::fail($msg);
+        }
+        if ($info->actPrice != $totalFee) {
+            $msg = "订单金额与回调通知金额不一致 orderSn:{$orderSn} {$info->actPrice} {$totalFee}";
+            Yii::info($msg);
+            util::fail($msg);
+        }
+        self::payAfter($info, $payWay);
+
+        $saleId = $info->saleId ?? 0;
+        $order = OrderClass::getById($saleId, true);
+        OrderService::payAfter($order, $payWay);
+    }
+
+    //第三方支付、余额支付和欠款支付后调用的流程 shish 2021.4.27
+    public static function payAfter($info, $payWay)
     {
-        //采购单失效
-        $purchase = PurchaseClass::cancel($id);
-        $saleId = $purchase->saleId;
-        //销售单失效
-        OrderClass::cancel($saleId);
+        if (empty($info)) {
+            util::fail('没有找到订单');
+        }
+        $deadline = $info->deadline;
+        if ($deadline <= date("Y-m-d H:i:s")) {
+            util::fail('订单已失效,请重新采购');
+        }
+        if (isset($info->status) == false || $info->status != PurchaseClass::STATUS_UN_PAY) {
+            util::fail('订单不是待付款状态');
+        }
+
+        /**零售采购单状态变化**/
+        $info->payWay = $payWay;
+        $info->status = PurchaseClass::STATUS_UN_SEND;
+        if ($payWay == dict::getDict('payWay', 'debtPay')) {
+            //欠款支付
+            $info->debt = 1;
+        }
+        $info->save();
+
+        /**零售门店资产变化**/
+        $shopId = $info['shopId'] ?? 0;
+        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+        $actPrice = $info->actPrice;
+        if ($payWay == dict::getDict('payWay', 'balancePay')) {
+            if (bccomp($actPrice, $shop->balance, 2) == 1) {
+                util::fail('余额不足');
+            }
+            $shop->balance = bcsub($shop->balance, $actPrice, 2);
+        }
+        $shop->totalPurchase = bcadd($shop->totalPurchase, $actPrice, 2);
+        $shop->cgUnPay -= 1;
+        $shop->cgUnSend += 1;
+        $shop->save();
+
+        /**零售的供货商资产变化**/
+        $ghsId = $info->ghsId ?? 0;
+        $ghs = Ghs::findBySql('select * from ' . Ghs::tableName() . ' where id = :id for update', ['id' => $ghsId])->one();
+        if (empty($ghs)) {
+            util::fail('没有找到供货商');
+        }
+        if ($payWay == dict::getDict('payWay', 'debtPay')) {
+            //欠款支付
+            $ghs->debt = 2;
+            $ghs->debtAmount = bcadd($ghs->debtAmount, $actPrice, 2);
+            $ghs->debtNum += 1;
+        }
+        $ghs->expendAmount = bcadd($ghs->expendAmount, $actPrice, 2);
+        $ghs->expendNum += 1;
+        $ghs->save();
     }
 
 }

+ 8 - 0
biz/admin/classes/AdminClass.php

@@ -16,4 +16,12 @@ class AdminClass extends BaseClass
     const OPEN_SHOP_CHECK = 2;
     const OPEN_SHOP_YES = 3;
 
+    //linqh 2021.5.14  [id=>adminData]
+    public static function getAdminMap($adminIds)
+    {
+        $where = [];
+        $where['id'] =  ['in', $adminIds];
+        $data = self::getAllByCondition($where,null,"*");
+        return array_column($data,null,"id");
+    }
 }

+ 31 - 2
biz/shop/classes/ShopAdminClass.php

@@ -86,7 +86,7 @@ class ShopAdminClass extends BaseClass
     //取店长 ssh 2021.1.8
     public static function getManager($shopId)
     {
-        $relate = self::getByCondition(['shopId' => $shopId]);
+        $relate = self::getByCondition(['shopId' => $shopId,'super'=>1]);
         $adminId = isset($relate['adminId']) ? $relate['adminId'] : 0;
         $info = [];
         if (!empty($adminId)) {
@@ -211,4 +211,33 @@ class ShopAdminClass extends BaseClass
         AdminRoleClass::counters(['num' => -1], ['id' => $relation->roleId]);
     }
 
-}
+    //根据shopId 获取 员工的shopAdminId
+
+
+
+    //通过shopId 获取相应的需要通知的 shopAdminIds (status=1 and delStatus=0 and remind=1)
+    public static function getRemindShopAdminIdsByShopId($shopId)
+    {
+        $where = [
+            'shopId'=>$shopId,
+            'status'=>1,
+            'delStatus'=>0,
+            'remind'=>1
+        ];
+        $data = self::getAllByCondition($where,null,"id");
+        return array_column($data,'id');
+    }
+
+    //通过shopId 获取相应的需要通知的 adminIds (status=1 and delStatus=0 and remind=1)
+    public static function getRemindAdminIdsByShopId($shopId)
+    {
+        $where = [
+            'shopId'=>$shopId,
+            'status'=>1,
+            'delStatus'=>0,
+            'remind'=>1
+        ];
+        $data = self::getAllByCondition($where,null,"adminId");
+        return array_column($data,'adminId');
+    }
+}

+ 21 - 0
biz/shop/classes/ShopCouponClass.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace biz\shop\classes;
+
+use biz\base\classes\BaseClass;
+
+class ShopCouponClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\shop\models\ShopCoupon';
+
+    const STATUS_UN_USE = 1;
+    const STATUS_USED = 2;
+    const STATUS_EXPIRE = 3;
+
+    public static function groupBaseInfo($list)
+    {
+        return $list;
+    }
+
+}

+ 15 - 0
biz/shop/models/ShopCoupon.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace biz\shop\models;
+
+use biz\base\models\Base;
+
+class ShopCoupon extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhShopCoupon';
+    }
+
+}

+ 24 - 0
biz/shop/services/ShopCouponService.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace biz\shop\services;
+
+use biz\base\services\BaseService;
+use biz\shop\classes\ShopCouponClass;
+
+class ShopCouponService extends BaseService
+{
+
+    public static $baseFile = '\biz\shop\classes\ShopCouponClass';
+
+    public static function getCouponList($where)
+    {
+        $data = ShopCouponClass::getList('*', $where, 'addTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+        $data['list'] = ShopCouponClass::groupBaseInfo($list);
+        return $data;
+    }
+
+}

+ 67 - 0
biz/tm/classes/TMessageClass.php

@@ -0,0 +1,67 @@
+<?php
+namespace biz\tm\classes;
+
+
+use biz\admin\classes\AdminClass;
+use biz\base\classes\BaseClass;
+use biz\shop\classes\ShopAdminClass;
+use bizHd\wx\classes\WxOpenClass;
+use Yii;
+class TMessageClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\tm\models\TMessage';
+
+
+    //供货商开单后, 其他员工和客户收下单通知  linqh 2021.5.14
+    //员工打开的是供货商的订单详情页
+    //客户打卡的是零售端的采购订单详情页
+    //https://mp.weixin.qq.com/advanced/tmplmsg?action=tmpl_preview&t=tmplmsg/preview&id=OPENTM417768700&token=1127184201&lang=zh_CN
+    /*
+     *
+    {{first.DATA}}
+    订购数量:{{keyword1.DATA}}
+    支付金额:{{keyword2.DATA}}
+    支付方式:{{keyword3.DATA}}
+    下单时间:{{keyword4.DATA}}
+    配送地址:{{keyword5.DATA}}
+    {{remark.DATA}}
+     */
+    public static function orderTMNotice($order)
+    {
+        if(empty($order)){
+            return;
+        }
+        $shortId = "OPENTM418105100";
+        //获取sj 下的所有开启通知的员工id
+        $shopId = $order['shopId']??0;
+        if(!$shopId){
+            return;
+        }
+        $ghsSjWx = WxOpenClass::getGhsWxInfo();
+        //根据门店获取员工
+        $adminIds = ShopAdminClass::getRemindAdminIdsByShopId($shopId);
+        $ghsNoticeData = [
+            "touser" => '',
+            "template_id" => $shortId,
+            "data" => [
+                "first" => ["value" => "下单通知。", "color" => "#173177"],
+                "keyword1" => ["value" => $order['bigNum'], "color" => "#173177"],
+                "keyword2" => ["value" => $order['actPrice'].'元', "color" => "#173177"],
+                "keyword3" => ["value" => $order['addTime'], "color" => "#173177"],
+                "remark" => ["value" => "点击查看详情", "color" => "#173177"]
+            ]
+        ];
+        if(empty($adminIds)){
+            //循环通知(慢?后续可加队列)
+            $adminMap = AdminClass::getAdminMap($adminIds);
+            foreach ($adminIds as $v){
+                $openid = $adminMap[$v]['openid']??'';
+                if(isset($adminMap[$v]) && $openid && $adminMap[$v]['subscribe']){
+
+                }
+            }
+        }
+
+    }
+}

+ 13 - 0
biz/tm/models/TMessage.php

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

+ 12 - 9
common/components/dict.php

@@ -9,6 +9,9 @@ class dict
 
     public static $data = [
 
+        //采购和销售单的有效期
+        'sale_purchase_order_valid' => 300,
+
         //需要显示国兰的信息 0不需要 1需要(要审核小程序请显示国兰信息)
         'showGlInfo' => 1,
         //显示零售和供货商的演示入口
@@ -116,15 +119,15 @@ class dict
 
         //模板消息 平台类型: 1花店,2供货商,3商城
         'tMessage' => [
-           1=>[
-                'OPENTM418105100'=>'下单成功通知',
-           ],
-           2=>[
-               'OPENTM418105100'=>'下单成功通知',
-           ],
-           3=>[
-               'OPENTM418105100'=>'下单成功通知',
-           ],
+            1 => [
+                'OPENTM418105100' => '下单成功通知',
+            ],
+            2 => [
+                'OPENTM418105100' => '下单成功通知',
+            ],
+            3 => [
+                'OPENTM418105100' => '下单成功通知',
+            ],
         ],
 
         //用户来源

+ 2 - 1
common/components/pay.php

@@ -6,6 +6,7 @@ use biz\recharge\classes\RechargeClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\classes\PurchaseClearClass;
+use bizHd\purchase\services\PurchaseService;
 use Yii;
 
 class pay
@@ -25,7 +26,7 @@ class pay
                     break;
                 case dict::getDict('capitalType', 'xhPurchase', 'id'):
                     //零售采购订单
-                    PurchaseClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
+                    PurchaseService::thirdPay($payWay, $orderSn, $totalFee, $attach);
                     break;
                 case dict::getDict('capitalType', 'hdPurchaseClear', 'id'):
                     //零售采购订单结算

+ 0 - 1
common/services/xhPayToolService.php

@@ -318,7 +318,6 @@ class xhPayToolService
             $updateData['wxPayType'] = $wxPayType;
             switch ($capitalType) {
                 case $capitalTypeList['xhOrder']['id']:
-                    //OrderClass::payAfter($order);
                     break;
                 case $capitalTypeList['xhActiveOrder']['id']://活动报名
                     xhActiveOrderService::updateById($orderId, $updateData);

+ 9 - 4
console/controllers/PurchaseController.php

@@ -5,14 +5,16 @@ namespace console\controllers;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\models\Purchase;
 use bizHd\purchase\services\PurchaseService;
+use common\components\noticeUtil;
 use yii\console\Controller;
 use Yii;
 
 class PurchaseController extends Controller
 {
 
-    //采购订单过期变更状态 shish 2021.5.14
+    //采购订单过期变更 shish 2021.5.14
     // ./yii purchase/expire-order
+    // /usr/local/nginx/html/huahuibao/yii purchase/expire-order
     public function actionExpireOrder()
     {
         $query = new \yii\db\Query();
@@ -27,9 +29,12 @@ class PurchaseController extends Controller
             foreach ($query->batch() as $purchases) {
                 foreach ($purchases as $purchase) {
                     $id = $purchase['id'] ?? 0;
-                    PurchaseService::expire($id);
+                    $current = PurchaseClass::getById($id, true);
+                    PurchaseService::expire($current);
+
                     $log = "过期的采购单:{$id} json:" . json_encode($purchase);
                     $arr[] = $log;
+
                 }
             }
             $transaction->commit();
@@ -40,9 +45,9 @@ class PurchaseController extends Controller
             }
         } catch (Exception $e) {
             $transaction->rollBack();
-            echo 'error';
+            $msg = $e->getMessage();
+            noticeUtil::push("采购订单过期变更报错:{$msg}", '15280215347');
         }
-        echo 'ok';
     }
 
 }

+ 11 - 1
sql.sql

@@ -2496,9 +2496,19 @@ ADD INDEX `idx_ptStyle` (`ptStyle`) ;
 -----shish 20210514
 ALTER TABLE xhPurchase MODIFY `status` TINYINT(2) NOT NULL DEFAULT '1' COMMENT '订单状态 1待付款,待确认,2待配送,3配送中,4已完成 5已取消';
 ALTER TABLE xhPurchase ADD INDEX expire(`status`,`deadline`);
-
+ALTER TABLE xhGhsOrder MODIFY `sendNum` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '配送编号,方便寻找订单对应的花材' AFTER `orderSn`;
+ALTER TABLE xhGhsOrder MODIFY `sendNum` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '配送编号,方便寻找订单对应的花材' AFTER `id`;
+ALTER TABLE xhShop ADD cgUnPay INT NOT NULL DEFAULT 0 COMMENT '采购待付款订单数' AFTER `totalPurchase`;
+ALTER TABLE xhShop ADD cgUnSend INT NOT NULL DEFAULT 0 COMMENT '采购待配送订单数' AFTER `cgUnPay`;
+ALTER TABLE xhShop ADD cgSending INT NOT NULL DEFAULT 0 COMMENT '采购配送中订单数' AFTER `cgUnSend`;
+ALTER TABLE xhShop ADD cgFinish INT NOT NULL DEFAULT 0 COMMENT '采购完成订单数' AFTER `cgSending`;
+ALTER TABLE xhShop ADD cgCancel INT NOT NULL DEFAULT 0 COMMENT '采购取消订单数' AFTER `cgFinish`;
+ALTER TABLE xhShopCoupon MODIFY `status` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '状态 1未使用 2使用 3过期';
 
 -----linqh 2021.5.14  监控ws定时任务
 */1 * * * * sh /root/new_monitor_shell/ws_monitor.sh >> /dev/null 2>&1
 
 
+-----shish 2021
+#采购单到期脚本
+*/1 * * * * /usr/local/nginx/html/huahuibao/yii purchase/expire-order