Procházet zdrojové kódy

Merge branch 'master' into zhongqi-ghsLimitBuyUpdate

shish před 4 týdny
rodič
revize
80bf6dc5a8

+ 1 - 1
app-ghs/controllers/ApplyController.php

@@ -29,7 +29,7 @@ class ApplyController extends BaseController
     {
         $get = Yii::$app->request->get();
         $mobile = $get['mobile'] ?? '';
-        if (stringUtil::isMobile($mobile) == false) {
+        if (!stringUtil::isMobile($mobile)) {
             util::fail('请输入正确手机号');
         }
         $rand = rand(11111, 99999);

+ 13 - 18
app-ghs/controllers/ConsoleController.php

@@ -30,21 +30,15 @@ class ConsoleController extends BaseController
         //$lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
         //$lsDebt = $lsDebt === null ? 0 : $lsDebt;
         //$totalDebt = bcadd($pfDebt, $lsDebt, 2);
-        $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,avCost,cost,virtualStock,delStatus', null, true);
-        $totalItemNum = 0;
-        $totalCost = 0;
-        if (!empty($itemList)) {
-            foreach ($itemList as $item) {
-                if ($item->virtualStock == 0 && $item->delStatus == 0) {
-                    $stock = $item->stock ?? 0;
-                    $cost = $item->avCost ?? 0;
-                    $totalItemNum = bcadd($stock, $totalItemNum, 2);
-                    $currentCost = bcmul($stock, $cost, 2);
-                    $totalCost = bcadd($currentCost, $totalCost, 2);
-                }
-            }
-        }
-        $totalItemNum = floor($totalItemNum);
+        // 优化慢查询:直接在数据库层聚合库存和成本,避免取出全量数据到PHP内存中循环计算
+        $stat = ItemClass::getByCondition(
+            ['mainId' => $this->mainId, 'virtualStock' => 0, 'delStatus' => 0],
+            false,
+            false,
+            'SUM(stock) as totalItemNum, SUM(stock * avCost) as totalCost'
+        );
+        $totalItemNum = floor($stat['totalItemNum'] ?? 0);
+        $totalCost = round($stat['totalCost'] ?? 0, 2);
         $totalBalance = CustomClass::sum(['ownMainId'=>$this->mainId],'balance');
         $may = $totalBalance<0 ? abs($totalBalance) : 0;
         $overview = [
@@ -244,7 +238,7 @@ class ConsoleController extends BaseController
             ["name" => "报损", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
             ["name" => "拆散", "img" => "ghs/home/kcyjs.png", "url" => "/admin/part/list"],
             ["name" => "收款流水", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/scanPay"],
-            ["name" => "收款码", "img" => "ghs/home/shop.png", "url" => "/admin/cg/code"]
+            ["name" => "公告", "img" => "ghs/home/icon_caigou.png", "url" => "/admin/ghsNotice/list"]
         ];
         $menuV3 = [
             ["name" => "商城码", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
@@ -266,7 +260,7 @@ class ConsoleController extends BaseController
             ["name" => "报损", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
             ["name" => "拆散", "img" => "ghs/home/kcyjs.png", "url" => "/admin/part/list"],
             ["name" => "收款流水", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/scanPay"],
-            ["name" => "收款码", "img" => "ghs/home/shop.png", "url" => "/admin/cg/code"]
+            ["name" => "公告", "img" => "ghs/home/icon_caigou.png", "url" => "/admin/ghsNotice/list"]
         ];
         $menuIconMap = [
             '商城码' => 'mall_code',
@@ -289,7 +283,7 @@ class ConsoleController extends BaseController
             '损耗' => 'breakage',
             '拆散' => 'break_up',
             '收款流水' => 'gather_record',
-            '收款码' => 'gather_code',
+            '公告' => 'purchase_record',
             '商城' => 'mall_code',
             '花材(简)' => 'item',
         ];
@@ -346,4 +340,5 @@ class ConsoleController extends BaseController
         util::success(['dict' => $dict, 'shop' => $shop]);
     }
 
+
 }

+ 120 - 0
app-ghs/controllers/GhsNoticeController.php

@@ -0,0 +1,120 @@
+<?php
+
+namespace ghs\controllers;
+
+use bizGhs\shop\classes\GhsNoticeClass;
+use common\components\util;
+use Yii;
+
+/**
+ * 批发端通知公告
+ */
+class GhsNoticeController extends BaseController
+{
+    /**
+     * 管理端公告列表
+     */
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $list = GhsNoticeClass::searchList([
+            'mainId' => $this->mainId,
+            'title' => $get['title'] ?? '',
+            'isDel' => 0,
+            'order' => 'id DESC',
+        ]);
+        util::success($list);
+    }
+
+    /**
+     * 客户端公告列表(仅显示中的公告)
+     */
+    public function actionShowList()
+    {
+        $get = Yii::$app->request->get();
+        $list = GhsNoticeClass::searchList([
+            'mainId' => $this->mainId,
+            'title' => $get['title'] ?? '',
+            'position' => $get['position'] ?? '',
+            'isDel' => 0,
+            'status' => 1,
+            'order' => 'sort DESC, id DESC',
+        ]);
+        util::success($list);
+    }
+
+    /**
+     * 新增公告
+     */
+    public function actionAdd()
+    {
+        $post = Yii::$app->request->post();
+        $post['mainId'] = $this->mainId;
+        $post['staffId'] = intval($this->shopAdminId);
+        $id = GhsNoticeClass::addNotice($post);
+        $info = GhsNoticeClass::getDetail($id);
+        util::success($info);
+    }
+
+    /**
+     * 更新公告
+     */
+    public function actionUpdate()
+    {
+        $post = Yii::$app->request->post();
+        $id = intval($post['id'] ?? 0);
+        if ($id <= 0) {
+            util::fail('公告id不对');
+        }
+        $info = GhsNoticeClass::getById($id);
+        GhsNoticeClass::valid($info, $this->mainId);
+        $post['staffId'] = intval($this->shopAdminId);
+        GhsNoticeClass::updateNotice($id, $post);
+        util::complete('修改成功');
+    }
+
+    /**
+     * 公告详情
+     */
+    public function actionDetail()
+    {
+        $id = intval(Yii::$app->request->get('id', 0));
+        if ($id <= 0) {
+            util::fail('公告id不对');
+        }
+        $info = GhsNoticeClass::getById($id);
+        GhsNoticeClass::valid($info, $this->mainId);
+        util::success(GhsNoticeClass::getDetail($id));
+    }
+
+    /**
+     * 软删除公告
+     */
+    public function actionDelete()
+    {
+        $id = intval(Yii::$app->request->post('id', Yii::$app->request->get('id', 0)));
+        if ($id <= 0) {
+            util::fail('公告id不对');
+        }
+        $info = GhsNoticeClass::getById($id);
+        GhsNoticeClass::valid($info, $this->mainId);
+        GhsNoticeClass::deleteNotice($id, intval($this->shopAdminId));
+        util::complete('删除成功');
+    }
+
+    /**
+     * 上下架公告
+     */
+    public function actionUpdateStatus()
+    {
+        $id = intval(Yii::$app->request->post('id', Yii::$app->request->get('id', 0)));
+        $status = intval(Yii::$app->request->post('status', Yii::$app->request->get('status', 0)));
+        if ($id <= 0) {
+            util::fail('公告id不对');
+        }
+        $info = GhsNoticeClass::getById($id);
+        GhsNoticeClass::valid($info, $this->mainId);
+        GhsNoticeClass::updateStatus($id, $status, intval($this->shopAdminId));
+        util::complete('操作成功');
+    }
+}

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

@@ -842,7 +842,7 @@ class TestController extends BaseController
 
     public function actionClearQuery()
     {
-        $shopId = 8249;
+        $shopId = 91064;
         $shop = ShopClass::getById($shopId, true);
         if (empty($shop)) {
             util::stop('没有找到门店信息呢');
@@ -858,12 +858,12 @@ class TestController extends BaseController
             'lklCertificatePath' => $lklCertificatePath,
         ];
         $laResource = new Lakala($params);
-        $orderSn = 'CL29416751';
+        $orderSn = 'CL29443345';
         $queryParams = [
             'orderSn' => $orderSn,
-            //'tradeNo' => '66222923861204',
+            'tradeNo' => '66224623283235',
         ];
-        $response = $laResource->query($queryParams, 0);
+        $response = $laResource->query($queryParams, 1);
         echo "<pre>";
         print_r($response);
         util::stop();

+ 13 - 1
app-ghs/controllers/TotalDebtChangeController.php

@@ -1,6 +1,7 @@
 <?php
 namespace ghs\controllers;
 use bizGhs\shop\classes\TotalDebtChangeClass;
+use common\components\dateUtil;
 use common\components\util;
 use Yii;
 
@@ -12,9 +13,20 @@ class TotalDebtChangeController extends BaseController
     //欠款变动明细
     public function actionList()
     {
-        //$get = Yii::$app->request->get();
+        $get = Yii::$app->request->get();
         $where = [];
         $where['mainId'] = $this->mainId;
+        $customId = $get['customId'] ?? 0;
+        if (!empty($customId)) {
+            $where['customId'] = (int)$customId;
+        }
+        $searchTime = $get['searchTime'] ?? '';
+        if (!empty($searchTime)) {
+            $startTime = $get['startTime'] ?? '';
+            $endTime = $get['endTime'] ?? '';
+            $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
+            $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
+        }
         $list = TotalDebtChangeClass::getChangeList($where);
         util::success($list);
     }

+ 1 - 1
app-hd/controllers/ApplyController.php

@@ -326,4 +326,4 @@ class ApplyController extends BaseController
         util::success(['code' => rand(1111, 9999)]);
     }
 
-}
+}

+ 9 - 15
app-hd/controllers/ConsoleController.php

@@ -22,21 +22,15 @@ class ConsoleController extends BaseController
     {
         //不要用缓存!!!!
 
-        $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,avCost,cost,virtualStock,delStatus', null, true);
-        $totalItemNum = 0;
-        $totalCost = 0;
-        if (!empty($itemList)) {
-            foreach ($itemList as $item) {
-                if ($item->virtualStock == 0 && $item->delStatus == 0) {
-                    $stock = $item->stock ?? 0;
-                    $cost = $item->avCost ?? 0;
-                    $totalItemNum = bcadd($stock, $totalItemNum, 2);
-                    $currentCost = bcmul($stock, $cost, 2);
-                    $totalCost = bcadd($currentCost, $totalCost, 2);
-                }
-            }
-        }
-        $totalItemNum = floor($totalItemNum);
+        // 优化慢查询:直接在数据库层聚合库存和成本,避免取出全量数据到PHP内存中循环计算
+        $stat = ItemClass::getByCondition(
+            ['mainId' => $this->mainId, 'virtualStock' => 0, 'delStatus' => 0],
+            false,
+            false,
+            'SUM(stock) as totalItemNum, SUM(stock * avCost) as totalCost'
+        );
+        $totalItemNum = floor($stat['totalItemNum'] ?? 0);
+        $totalCost = round($stat['totalCost'] ?? 0, 2);
         $goodsCount = GoodsClass::getCount(['mainId' => $this->mainId]);
         $customCount = CustomClass::getCount(['shopId' => $this->shopId]);
         $orderCount = OrderClass::getCount(['mainId' => $this->mainId, 'status' => 4]);

+ 61 - 1
app-hd/controllers/GhsController.php

@@ -8,6 +8,7 @@ use bizGhs\custom\classes\AccountMoneyClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\classes\CustomLevelClass;
 use bizGhs\merchant\classes\WlClass;
+use bizGhs\shop\classes\GhsNoticeClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\shop\classes\ShopExtClass;
 use bizGhs\stat\classes\StatVisitClass;
@@ -23,7 +24,7 @@ use Yii;
 class GhsController extends BaseController
 {
 
-    public $guestAccess = ['info', 'get-ghs-data', 'detail'];
+    public $guestAccess = ['info', 'get-ghs-data', 'detail', 'common-info', 'ghs-notice-detail'];
 
     //提示花店有多个供货商
     public function actionRemindMoreGhs()
@@ -496,4 +497,63 @@ class GhsController extends BaseController
         util::complete();
     }
 
+    public function actionCommonInfo()
+    {
+        $mainId = $this->resolveGhsMainId();
+        // 通用接口返回全部有效公告,前端按 positions 字段筛选展示位置
+        $ghsNoticeList = GhsNoticeClass::getClientNoticeList($mainId);
+        util::success(['ghsNoticeList' => $ghsNoticeList]);
+    }
+
+    /**
+     * 批发商公告详情(零售端采购页查看)
+     */
+    public function actionGhsNoticeDetail()
+    {
+        $id = intval(Yii::$app->request->get('id', 0));
+        if ($id <= 0) {
+            util::fail('公告id不对');
+        }
+        util::success(GhsNoticeClass::getClientDetail($id));
+    }
+
+    /**
+     * 根据批发商 ghsId 或 shopId 解析 mainId(列表接口用,勿与公告 id 混用)
+     */
+    protected function resolveGhsMainId(): int
+    {
+        $get = Yii::$app->request->get();
+        $ghsId = intval($get['ghsId'] ?? 0);
+        $shopId = intval($get['shopId'] ?? 0);
+        $ghsShopId = 0;
+
+        if ($ghsId > 0) {
+            $ghs = GhsClass::getById($ghsId);
+            if (empty($ghs)) {
+                util::fail('没有找到批发商');
+            }
+            if (!empty($this->shopId)) {
+                GhsClass::valid($ghs, $this->shopId);
+            }
+            $ghsShopId = intval($ghs['shopId'] ?? 0);
+        } elseif ($shopId > 0) {
+            $ghsShop = ShopClass::getById($shopId, true);
+            if (empty($ghsShop) || $ghsShop->ptStyle != dict::getDict('ptStyle', 'ghs')) {
+                util::fail('没有找到批发店');
+            }
+            $ghsShopId = $shopId;
+        } else {
+            util::fail('参数不对');
+        }
+
+        $ghsShop = ShopClass::getById($ghsShopId, true);
+        if (empty($ghsShop)) {
+            util::fail('没有找到批发商');
+        }
+        $mainId = intval($ghsShop->mainId ?? 0);
+        if ($mainId <= 0) {
+            util::fail('批发商信息不完整');
+        }
+        return $mainId;
+    }
 }

+ 12 - 1
app-hd/controllers/OrderController.php

@@ -35,6 +35,7 @@ use bizHd\promote\services\CouponService;
 use common\components\httpUtil;
 use biz\wx\classes\WxMessageClass;
 use common\components\lakala\Lakala;
+use yii\helpers\ArrayHelper;
 
 class OrderController extends BaseController
 {
@@ -270,6 +271,16 @@ class OrderController extends BaseController
         util::complete('操作成功');
     }
 
+    //批量确认取货 待发货的自取订单 每次500个
+    public function actionBatchFetch()
+    {
+        $where = ["status" => 2, "sendType" => 1, "shopId" => $this->shopId];
+        $orderList = OrderService::getLimitList("id",$where,500,"id desc");
+        $ids = ArrayHelper::getColumn($orderList,"id");
+        OrderService::updateByIds($ids, ["status" => 4]);
+        util::complete($ids);
+    }
+
     //确认发货
     public function actionSend()
     {
@@ -1486,4 +1497,4 @@ class OrderController extends BaseController
         util::success(['sedCost' => 10]);
     }
 
-}
+}

+ 7 - 0
app-hd/controllers/PurchaseController.php

@@ -726,6 +726,13 @@ class PurchaseController extends BaseController
                             util::fail('请返回选择 必选商品');
                         }
                     }
+                    if ($ghsShopId == 100883) {
+                        $hasMust = array_intersect($ids, [5017957,5036067,5036089,5036099,5017958,5036063,5017948,5035980,5036073,5036075,5036076,5036117,5036118,5017949,5035979,5035976,5035928,5035930,5036061,5035879]);
+                        if (empty($hasMust)) {
+                            util::fail('请返回选择 必选商品');
+                        }
+                    }
+
 
                     //三明易批花
                     if ($ghsShopId == 82200) {

+ 120 - 0
app-hd/controllers/ShopNoticeController.php

@@ -0,0 +1,120 @@
+<?php
+
+namespace hd\controllers;
+
+use bizHd\shop\classes\ShopNoticeClass;
+use common\components\util;
+use Yii;
+
+/**
+ * 零售花店通知公告
+ */
+class ShopNoticeController extends BaseController
+{
+    /**
+     * 管理端公告列表
+     */
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $list = ShopNoticeClass::searchList([
+            'mainId' => $this->mainId,
+            'title' => $get['title'] ?? '',
+            'isDel' => 0,
+            'order' => 'id DESC',
+        ]);
+        util::success($list);
+    }
+
+    /**
+     * 客户端公告列表(仅显示中的公告)
+     */
+    public function actionShowList()
+    {
+        $get = Yii::$app->request->get();
+        $list = ShopNoticeClass::searchList([
+            'mainId' => $this->mainId,
+            'title' => $get['title'] ?? '',
+            'position' => $get['position'] ?? '',
+            'isDel' => 0,
+            'status' => 1,
+            'order' => 'sort DESC, id DESC',
+        ]);
+        util::success($list);
+    }
+
+    /**
+     * 新增公告
+     */
+    public function actionAdd()
+    {
+        $post = Yii::$app->request->post();
+        $post['mainId'] = $this->mainId;
+        $post['staffId'] = intval($this->shopAdminId);
+        $id = ShopNoticeClass::addNotice($post);
+        $info = ShopNoticeClass::getDetail($id);
+        util::success($info);
+    }
+
+    /**
+     * 更新公告
+     */
+    public function actionUpdate()
+    {
+        $post = Yii::$app->request->post();
+        $id = intval($post['id'] ?? 0);
+        if ($id <= 0) {
+            util::fail('公告id不对');
+        }
+        $info = ShopNoticeClass::getById($id);
+        ShopNoticeClass::valid($info, $this->mainId);
+        $post['staffId'] = intval($this->shopAdminId);
+        ShopNoticeClass::updateNotice($id, $post);
+        util::complete('修改成功');
+    }
+
+    /**
+     * 公告详情
+     */
+    public function actionDetail()
+    {
+        $id = intval(Yii::$app->request->get('id', 0));
+        if ($id <= 0) {
+            util::fail('公告id不对');
+        }
+        $info = ShopNoticeClass::getById($id);
+        ShopNoticeClass::valid($info, $this->mainId);
+        util::success(ShopNoticeClass::getDetail($id));
+    }
+
+    /**
+     * 软删除公告
+     */
+    public function actionDelete()
+    {
+        $id = intval(Yii::$app->request->post('id', Yii::$app->request->get('id', 0)));
+        if ($id <= 0) {
+            util::fail('公告id不对');
+        }
+        $info = ShopNoticeClass::getById($id);
+        ShopNoticeClass::valid($info, $this->mainId);
+        ShopNoticeClass::deleteNotice($id, intval($this->shopAdminId));
+        util::complete('删除成功');
+    }
+
+    /**
+     * 上下架公告
+     */
+    public function actionUpdateStatus()
+    {
+        $id = intval(Yii::$app->request->post('id', Yii::$app->request->get('id', 0)));
+        $status = intval(Yii::$app->request->post('status', Yii::$app->request->get('status', 0)));
+        if ($id <= 0) {
+            util::fail('公告id不对');
+        }
+        $info = ShopNoticeClass::getById($id);
+        ShopNoticeClass::valid($info, $this->mainId);
+        ShopNoticeClass::updateStatus($id, $status, intval($this->shopAdminId));
+        util::complete('操作成功');
+    }
+}

+ 15 - 5
app-mall/controllers/OrderController.php

@@ -38,6 +38,16 @@ class OrderController extends BaseController
     //二维码收款使用
     public $guestAccess = ['order-relate', 'fast-pay'];
 
+    public function actionInform()
+    {
+        $get = Yii::$app->request->get();
+        $hdId = $get['hdId'] ?? 0;
+        $account = $get['account'] ?? 0;
+        $page = $get['page'] ?? '';
+        $userId = $this->userId;
+        noticeUtil::push("零售客户下单报错 hdId:{$hdId} account:{$account} userId:{$userId} page:{$page}", '15280215347');
+    }
+
     //记账单列表 ssh 20250627
     public function actionDebtList()
     {
@@ -493,8 +503,8 @@ class OrderController extends BaseController
                         util::fail("不满足最低消费金额{$hb->minConsume}元");
                     }
                     if ($this->shop->rechargeWeal == 3) {
-                        if(bccomp($custom->balance, $modifyPrice) == -1) {
-							//不要限制提交
+                        if (bccomp($custom->balance, $modifyPrice) == -1) {
+                            //不要限制提交
                             //util::fail('此红包非余额支付不可用(您的余额不足)');
                         }
                     }
@@ -826,7 +836,7 @@ class OrderController extends BaseController
                         util::fail("不满足最低消费金额{$hb->minConsume}元");
                     }
                     if ($this->shop->rechargeWeal == 3) {
-                        if($custom->balance < $modifyPrice) {
+                        if ($custom->balance < $modifyPrice) {
                             util::fail('此红包非余额支付不可用(您的余额不足)');
                         }
                     }
@@ -867,7 +877,7 @@ class OrderController extends BaseController
                 $hb->orderId = $return->id;
                 $hb->save();
             }
-            
+
             $orderId = $return->id;
             $orderSn = $return->orderSn;
             $actPrice = $return->actPrice ?? 0;
@@ -921,7 +931,7 @@ class OrderController extends BaseController
             }
             //支付前验证订单有效性
             OrderService::checkBeforePay($order);
-            
+
             $payWay = dict::getDict('payWay', 'balancePay');
             \bizHd\order\classes\OrderClass::payAfter($order, $payWay);
             $transaction->commit();

+ 288 - 0
biz-ghs/shop/classes/GhsNoticeClass.php

@@ -0,0 +1,288 @@
+<?php
+
+namespace bizGhs\shop\classes;
+
+use bizGhs\base\classes\BaseClass;
+use common\components\util;
+use Yii;
+use yii\db\Expression;
+
+/**
+ * 批发端通知公告业务类
+ */
+class GhsNoticeClass extends BaseClass
+{
+    public static $baseFile = '\bizGhs\shop\models\GhsNotice';
+
+    /** 展示位置:分类菜单 */
+    const POSITION_CATEGORY = 1;
+    /** 展示位置:订单提交 */
+    const POSITION_ORDER = 2;
+
+    /**
+     * 展示位置文案映射
+     */
+    public static function getPositionMap(): array
+    {
+        return [
+            self::POSITION_CATEGORY => '分类菜单',
+            self::POSITION_ORDER => '订单提交',
+        ];
+    }
+
+    /**
+     * 客户端公告列表(不分页)
+     */
+    public static function getClientNoticeList(int $mainId, int $position = 0): array
+    {
+        if ($mainId <= 0) {
+            return [];
+        }
+        $query = self::getModel()::find()
+            ->where(['mainId' => $mainId, 'isDel' => 0, 'status' => 1]);
+        if ($position > 0) {
+            $query->andWhere(new Expression('FIND_IN_SET(:position, [[position]])', [':position' => (string)$position]));
+        }
+        $list = $query->orderBy('sort DESC, id DESC')->asArray()->all();
+        return self::groupBaseInfo($list);
+    }
+
+    /**
+     * 客户端公告详情(仅校验公告本身有效)
+     */
+    public static function getClientDetail(int $id): array
+    {
+        $info = self::getById($id);
+        if (empty($info) || intval($info['isDel']) === 1 || intval($info['status']) !== 1) {
+            util::fail('公告不存在');
+        }
+        return self::getDetail($id);
+    }
+
+    /**
+     * 通用列表查询,供管理端与客户端复用
+     */
+    public static function searchList(array $params): array
+    {
+        $get = Yii::$app->request->get();
+        $page = isset($get['page']) ? max(1, intval($get['page'])) : 1;
+        $pageSize = !empty($get['pageSize']) ? intval($get['pageSize']) : Yii::$app->params['pageSize'];
+
+        $query = self::getModel()::find()->where(['mainId' => intval($params['mainId'])]);
+
+        if (isset($params['isDel'])) {
+            $query->andWhere(['isDel' => intval($params['isDel'])]);
+        }
+        if (isset($params['status'])) {
+            $query->andWhere(['status' => intval($params['status'])]);
+        }
+        if (!empty($params['title'])) {
+            $query->andWhere(['like', 'title', trim($params['title'])]);
+        }
+        if (!empty($params['position'])) {
+            $position = intval($params['position']);
+            $query->andWhere(new Expression('FIND_IN_SET(:position, [[position]])', [':position' => (string)$position]));
+        }
+
+        $order = !empty($params['order']) ? $params['order'] : 'id DESC';
+        $totalNum = (int)$query->count();
+        $totalPage = $pageSize > 0 ? (int)ceil($totalNum / $pageSize) : 0;
+        $list = $query->orderBy($order)
+            ->offset(($page - 1) * $pageSize)
+            ->limit($pageSize)
+            ->asArray()
+            ->all();
+
+        return [
+            'totalNum' => $totalNum,
+            'totalPage' => $totalPage,
+            'moreData' => $page < $totalPage ? 1 : 0,
+            'list' => self::groupBaseInfo($list),
+        ];
+    }
+
+    /**
+     * 组装列表展示字段
+     */
+    public static function groupBaseInfo(array $list): array
+    {
+        $positionMap = self::getPositionMap();
+        foreach ($list as $key => $item) {
+            $positions = self::formatPositionToArr($item['position'] ?? '');
+            $labels = [];
+            foreach ($positions as $pos) {
+                if (isset($positionMap[$pos])) {
+                    $labels[] = $positionMap[$pos];
+                }
+            }
+            $list[$key]['positions'] = $positions;
+            $list[$key]['positionLabels'] = $labels;
+        }
+        return $list;
+    }
+
+    /**
+     * 多选位置转逗号分隔字符串
+     */
+    public static function formatPositionToStr($positions): string
+    {
+        if (is_string($positions)) {
+            $positions = array_filter(array_map('trim', explode(',', $positions)));
+        }
+        if (!is_array($positions)) {
+            return '';
+        }
+        $valid = array_keys(self::getPositionMap());
+        $positions = array_values(array_unique(array_map('intval', $positions)));
+        $positions = array_values(array_intersect($positions, $valid));
+        sort($positions);
+        return implode(',', $positions);
+    }
+
+    /**
+     * 逗号分隔字符串转位置数组
+     */
+    public static function formatPositionToArr(string $position): array
+    {
+        if ($position === '') {
+            return [];
+        }
+        $positions = array_filter(array_map('trim', explode(',', $position)));
+        return array_values(array_map('intval', $positions));
+    }
+
+    /**
+     * 校验公告表单数据
+     */
+    public static function validateNoticeData(array $data): array
+    {
+        $title = trim($data['title'] ?? '');
+        $summary = trim($data['summary'] ?? '');
+        if ($title === '') {
+            util::fail('请输入公告标题');
+        }
+        if (mb_strlen($title) > 20) {
+            util::fail('标题不能超过20个字');
+        }
+        if ($summary === '') {
+            util::fail('请输入公告简介');
+        }
+        if (mb_strlen($summary) > 70) {
+            util::fail('公告简介不能超过70个字');
+        }
+
+        $position = self::formatPositionToStr($data['position'] ?? '');
+        if ($position === '') {
+            util::fail('请选择展示位置');
+        }
+
+        $content = $data['content'] ?? '';
+        if ($content === '' || $content === '[]') {
+            util::fail('请添加公告内容');
+        }
+        if (is_string($content)) {
+            $contentArr = json_decode($content, true);
+            if (!is_array($contentArr) || empty($contentArr)) {
+                util::fail('公告内容格式不正确');
+            }
+        }
+
+        return [
+            'title' => $title,
+            'summary' => $summary,
+            'content' => is_string($content) ? $content : json_encode($content, JSON_UNESCAPED_UNICODE),
+            'position' => $position,
+            'sort' => intval($data['sort'] ?? 0),
+            'status' => intval($data['status'] ?? 1) === 1 ? 1 : 0,
+        ];
+    }
+
+    /**
+     * 新增公告
+     */
+    public static function addNotice(array $data): int
+    {
+        $noticeData = self::validateNoticeData($data);
+        if (!empty($data['mainId'])) {
+            $noticeData['mainId'] = intval($data['mainId']);
+        }
+        if (!empty($data['staffId'])) {
+            $noticeData['staffId'] = intval($data['staffId']);
+        }
+        if ($noticeData['status'] === 1) {
+            $noticeData['publishTime'] = date('Y-m-d H:i:s');
+        }
+        $result = self::add($noticeData);
+        return is_array($result) ? intval($result['id'] ?? 0) : intval($result);
+    }
+
+    /**
+     * 更新公告
+     */
+    public static function updateNotice(int $id, array $data): void
+    {
+        $noticeData = self::validateNoticeData($data);
+        $info = self::getById($id);
+        if (empty($info)) {
+            util::fail('公告不存在');
+        }
+        if (!empty($data['staffId'])) {
+            $noticeData['staffId'] = intval($data['staffId']);
+        }
+        self::updateById($id, $noticeData);
+    }
+
+    /**
+     * 公告详情
+     */
+    public static function getDetail(int $id): array
+    {
+        $info = self::getById($id);
+        if (empty($info)) {
+            util::fail('公告不存在');
+        }
+        $list = self::groupBaseInfo([$info]);
+        return current($list);
+    }
+
+    /**
+     * 软删除公告
+     */
+    public static function deleteNotice(int $id, int $staffId = 0): void
+    {
+        $updateData = ['isDel' => 1];
+        if ($staffId > 0) {
+            $updateData['staffId'] = $staffId;
+        }
+        self::updateById($id, $updateData);
+    }
+
+    /**
+     * 上下架公告
+     */
+    public static function updateStatus(int $id, int $status, int $staffId = 0): void
+    {
+        $status = $status === 1 ? 1 : 0;
+        $updateData = ['status' => $status];
+        if ($status === 1) {
+            $updateData['publishTime'] = date('Y-m-d H:i:s');
+        }
+        if ($staffId > 0) {
+            $updateData['staffId'] = $staffId;
+        }
+        self::updateById($id, $updateData);
+    }
+
+    /**
+     * 校验公告归属权限
+     */
+    public static function valid(array $info, int $mainId): void
+    {
+        if (empty($info) || intval($info['mainId']) !== intval($mainId)) {
+            util::fail('没有权限操作该公告');
+        }
+        if (intval($info['isDel']) === 1) {
+            util::fail('公告已删除');
+        }
+    }
+}

+ 16 - 0
biz-ghs/shop/models/GhsNotice.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace bizGhs\shop\models;
+
+use bizGhs\base\models\Base;
+
+/**
+ * 批发端通知公告
+ */
+class GhsNotice extends Base
+{
+    public static function tableName()
+    {
+        return 'xhGhsNotice';
+    }
+}

+ 262 - 0
biz-hd/shop/classes/ShopNoticeClass.php

@@ -0,0 +1,262 @@
+<?php
+
+namespace bizHd\shop\classes;
+
+use bizHd\base\classes\BaseClass;
+use common\components\util;
+use Yii;
+use yii\db\Expression;
+
+/**
+ * 零售花店通知公告业务类
+ */
+class ShopNoticeClass extends BaseClass
+{
+    public static $baseFile = '\bizHd\shop\models\ShopNotice';
+
+    /** 展示位置:商城首页 */
+    const POSITION_HOME = 1;
+    /** 展示位置:分类菜单 */
+    const POSITION_CATEGORY = 2;
+    /** 展示位置:购物车 */
+    const POSITION_CART = 4;
+    /** 展示位置:订单提交 */
+    const POSITION_ORDER = 8;
+
+    /**
+     * 展示位置文案映射
+     */
+    public static function getPositionMap(): array
+    {
+        return [
+            self::POSITION_HOME => '商城首页',
+            self::POSITION_CATEGORY => '分类菜单',
+            self::POSITION_CART => '购物车',
+            self::POSITION_ORDER => '订单提交',
+        ];
+    }
+
+    /**
+     * 通用列表查询,供管理端与客户端复用
+     */
+    public static function searchList(array $params): array
+    {
+        $get = Yii::$app->request->get();
+        $page = isset($get['page']) ? max(1, intval($get['page'])) : 1;
+        $pageSize = !empty($get['pageSize']) ? intval($get['pageSize']) : Yii::$app->params['pageSize'];
+
+        $query = self::getModel()::find()->where(['mainId' => intval($params['mainId'])]);
+
+        if (isset($params['isDel'])) {
+            $query->andWhere(['isDel' => intval($params['isDel'])]);
+        }
+        if (isset($params['status'])) {
+            $query->andWhere(['status' => intval($params['status'])]);
+        }
+        if (!empty($params['title'])) {
+            $query->andWhere(['like', 'title', trim($params['title'])]);
+        }
+        if (!empty($params['position'])) {
+            $position = intval($params['position']);
+            $query->andWhere(new Expression('FIND_IN_SET(:position, [[position]])', [':position' => (string)$position]));
+        }
+
+        $order = !empty($params['order']) ? $params['order'] : 'id DESC';
+        $totalNum = (int)$query->count();
+        $totalPage = $pageSize > 0 ? (int)ceil($totalNum / $pageSize) : 0;
+        $list = $query->orderBy($order)
+            ->offset(($page - 1) * $pageSize)
+            ->limit($pageSize)
+            ->asArray()
+            ->all();
+
+        return [
+            'totalNum' => $totalNum,
+            'totalPage' => $totalPage,
+            'moreData' => $page < $totalPage ? 1 : 0,
+            'list' => self::groupBaseInfo($list),
+        ];
+    }
+
+    /**
+     * 组装列表展示字段
+     */
+    public static function groupBaseInfo(array $list): array
+    {
+        $positionMap = self::getPositionMap();
+        foreach ($list as $key => $item) {
+            $positions = self::formatPositionToArr($item['position'] ?? '');
+            $labels = [];
+            foreach ($positions as $pos) {
+                if (isset($positionMap[$pos])) {
+                    $labels[] = $positionMap[$pos];
+                }
+            }
+            $list[$key]['positions'] = $positions;
+            $list[$key]['positionLabels'] = $labels;
+        }
+        return $list;
+    }
+
+    /**
+     * 多选位置转逗号分隔字符串
+     */
+    public static function formatPositionToStr($positions): string
+    {
+        if (is_string($positions)) {
+            $positions = array_filter(array_map('trim', explode(',', $positions)));
+        }
+        if (!is_array($positions)) {
+            return '';
+        }
+        $valid = array_keys(self::getPositionMap());
+        $positions = array_values(array_unique(array_map('intval', $positions)));
+        $positions = array_values(array_intersect($positions, $valid));
+        sort($positions);
+        return implode(',', $positions);
+    }
+
+    /**
+     * 逗号分隔字符串转位置数组
+     */
+    public static function formatPositionToArr(string $position): array
+    {
+        if ($position === '') {
+            return [];
+        }
+        $positions = array_filter(array_map('trim', explode(',', $position)));
+        return array_values(array_map('intval', $positions));
+    }
+
+    /**
+     * 校验公告表单数据
+     */
+    public static function validateNoticeData(array $data): array
+    {
+        $title = trim($data['title'] ?? '');
+        $summary = trim($data['summary'] ?? '');
+        if ($title === '') {
+            util::fail('请输入公告标题');
+        }
+        if (mb_strlen($title) > 20) {
+            util::fail('标题不能超过20个字');
+        }
+        if ($summary === '') {
+            util::fail('请输入公告简介');
+        }
+        if (mb_strlen($summary) > 200) {
+            util::fail('公告简介不能超过200个字');
+        }
+
+        $position = self::formatPositionToStr($data['position'] ?? '');
+        if ($position === '') {
+            util::fail('请选择展示位置');
+        }
+
+        $content = $data['content'] ?? '';
+        if ($content === '' || $content === '[]') {
+            util::fail('请添加公告内容');
+        }
+        if (is_string($content)) {
+            $contentArr = json_decode($content, true);
+            if (!is_array($contentArr) || empty($contentArr)) {
+                util::fail('公告内容格式不正确');
+            }
+        }
+
+        return [
+            'title' => $title,
+            'summary' => $summary,
+            'content' => is_string($content) ? $content : json_encode($content, JSON_UNESCAPED_UNICODE),
+            'position' => $position,
+            'sort' => intval($data['sort'] ?? 0),
+            'status' => intval($data['status'] ?? 1) === 1 ? 1 : 0,
+        ];
+    }
+
+    /**
+     * 新增公告
+     */
+    public static function addNotice(array $data): int
+    {
+        $noticeData = self::validateNoticeData($data);
+        if (!empty($data['mainId'])) {
+            $noticeData['mainId'] = intval($data['mainId']);
+        }
+        if (!empty($data['staffId'])) {
+            $noticeData['staffId'] = intval($data['staffId']);
+        }
+        if ($noticeData['status'] === 1) {
+            $noticeData['publishTime'] = date('Y-m-d H:i:s');
+        }
+        $result = self::add($noticeData);
+        return is_array($result) ? intval($result['id'] ?? 0) : intval($result);
+    }
+
+    /**
+     * 更新公告
+     */
+    public static function updateNotice(int $id, array $data): void
+    {
+        $noticeData = self::validateNoticeData($data);
+        $info = self::getById($id);
+        if (empty($info)) {
+            util::fail('公告不存在');
+        }
+        if (!empty($data['staffId'])) {
+            $noticeData['staffId'] = intval($data['staffId']);
+        }
+        self::updateById($id, $noticeData);
+    }
+
+    /**
+     * 公告详情
+     */
+    public static function getDetail(int $id): array
+    {
+        $info = self::getById($id);
+        if (empty($info)) {
+            util::fail('公告不存在');
+        }
+        $list = self::groupBaseInfo([$info]);
+        return current($list);
+    }
+
+    /**
+     * 软删除公告
+     */
+    public static function deleteNotice(int $id, int $staffId = 0): void
+    {
+        $updateData = ['isDel' => 1];
+        if ($staffId > 0) {
+            $updateData['staffId'] = $staffId;
+        }
+        self::updateById($id, $updateData);
+    }
+
+    /**
+     * 上下架公告
+     */
+    public static function updateStatus(int $id, int $status, int $staffId = 0): void
+    {
+        $status = $status === 1 ? 1 : 0;
+        $updateData = ['status' => $status];
+        if ($staffId > 0) {
+            $updateData['staffId'] = $staffId;
+        }
+        self::updateById($id, $updateData);
+    }
+
+    /**
+     * 校验公告归属权限
+     */
+    public static function valid(array $info, int $mainId): void
+    {
+        if (empty($info) || intval($info['mainId']) !== intval($mainId)) {
+            util::fail('没有权限操作该公告');
+        }
+        if (intval($info['isDel']) === 1) {
+            util::fail('公告已删除');
+        }
+    }
+}

+ 16 - 0
biz-hd/shop/models/ShopNotice.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace bizHd\shop\models;
+
+use bizHd\base\models\Base;
+
+/**
+ * 零售花店通知公告
+ */
+class ShopNotice extends Base
+{
+    public static function tableName()
+    {
+        return 'xhShopNotice';
+    }
+}

+ 1 - 1
biz/shop/classes/ShopClass.php

@@ -562,7 +562,7 @@ class ShopClass extends BaseClass
         ShopYeChangeClass::addChange($change, true);
 
         //平台余额增加
-        PtAssetClass::customKdAddBalance($shop, $amount, $order, $capitalType, $tx);
+        //PtAssetClass::customKdAddBalance($shop, $amount, $order, $capitalType, $tx);
     }
 
     public static function customScanPayAddBalance($main, $shop, $amount, $order, $capitalType)

+ 2 - 0
common/components/constant.php

@@ -18,6 +18,8 @@ class constant
 				['name' => '本月', 'value' => 'thisMonth',],
 				['name' => '上月', 'value' => 'lastMonth',],
 				['name' => '今年', 'value' => 'thisYear',],
+				['name' => '近一周', 'value' => 'last7Days',],
+				['name' => '近30天', 'value' => 'last30Days',],
 				['name' => '自定义', 'value' => 'custom',],
 			],
 		];

+ 18 - 0
common/components/dateUtil.php

@@ -56,6 +56,24 @@ class dateUtil
                     $endTime = date("Ymd", mktime(23, 59, 59, 1, 0, date("Y", strtotime('+1 year'))));
                 }
                 break;
+            case 'last7Days':
+                //近一周(含今天)
+                $startTime = date("Y-m-d 00:00:00", strtotime("-6 days"));
+                $endTime = date("Y-m-d 23:59:59");
+                if ($Stat) {
+                    $startTime = date("Ymd", strtotime("-6 days"));
+                    $endTime = date("Ymd");
+                }
+                break;
+            case 'last30Days':
+                //近30天(含今天)
+                $startTime = date("Y-m-d 00:00:00", strtotime("-29 days"));
+                $endTime = date("Y-m-d 23:59:59");
+                if ($Stat) {
+                    $startTime = date("Ymd", strtotime("-29 days"));
+                    $endTime = date("Ymd");
+                }
+                break;
             case 'lastWeek':
                 //上周
                 $startTime = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d") - date("w") + 1 - 7, date("Y")));

+ 2 - 0
common/components/dict.php

@@ -305,6 +305,8 @@ class dict
             ['name' => '本月', 'value' => 'thisMonth',],
             ['name' => '上月', 'value' => 'lastMonth',],
             ['name' => '今年', 'value' => 'thisYear',],
+            ['name' => '近一周', 'value' => 'last7Days',],
+            ['name' => '近30天', 'value' => 'last30Days',],
         ],
 
         //所属平台类型

+ 2 - 2
common/components/sms.php

@@ -89,7 +89,7 @@ class sms
             util::fail('没有找到平台');
         }
         //$name = isset($open['name']) ? $open['name'] : '花卉宝';
-        $name = '花掌柜';
+        $name = '厦门中花汇';
         $sign = isset($merchant) == true ? "【{$merchant['name']}】" : "【{$name}】";
         $msg = $sign . $msg;
 
@@ -116,4 +116,4 @@ class sms
         $sms->sendVariableSMS($msg, $params);
     }
 
-}
+}

+ 2 - 2
console/controllers/ItemController.php

@@ -40,8 +40,8 @@ class ItemController extends Controller
     public function actionMigrate()
     {
         if (getenv('YII_ENV') == 'production') {
-            $newMainId = 97789;
-            $oldMainId = 42940;
+            $newMainId = 100880;
+            $oldMainId = 16299;
         } else {
             $newMainId = 762;
             $oldMainId = 644;