Просмотр исходного кода

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

shizhongqi 2 месяцев назад
Родитель
Сommit
99f55c1e8c

+ 13 - 0
.gitattributes

@@ -3,3 +3,16 @@
 /.scrutinizer.yml   export-ignore
 /.travis.yml        export-ignore
 /docs               export-ignore
+
+# 统一换行符,避免仅 CRLF/LF 差异被 Git 识别为修改
+* text=auto
+
+*.php text eol=lf
+*.js text eol=lf
+*.json text eol=lf
+*.md text eol=lf
+*.yml text eol=lf
+*.yaml text eol=lf
+*.xml text eol=lf
+*.sql text eol=lf
+

+ 1 - 0
.gitignore

@@ -3,6 +3,7 @@
 .buildpath
 .project
 .cursor
+.editorconfig
 
 console/runtime/
 

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

@@ -173,7 +173,7 @@ class ConsoleController extends BaseController
         }
 
         //$notice[] = ['title' => '客户多个订单开始支持一键分享', 'action' => '查看', 'page' => '/admin/book/detail?id=calc'];
-        $notice[] = ['title' => '如果你发现一个问题很重要,一直没给你处理,在小群多反应几次,用反应次数强调重要性,目前批发店多反应问题多,都在排队。', 'action' => '', 'page' => ''];
+        //$notice[] = ['title' => '如果你发现一个问题很重要,一直没给你处理,在小群多反应几次,用反应次数强调重要性,目前批发店多反应问题多,都在排队。', 'action' => '', 'page' => ''];
         //$notice[] = ['title' => '新功能:客户端和后台使用跑腿的流程', 'action' => '', 'page' => '/admin/book/detail?id=use_pt'];
         //$notice[] = ['title' => '分享订单打不开的解决办法', 'action' => '查看', 'page' => '/admin/book/detail?id=calc'];
 

+ 3 - 0
app-ghs/controllers/DistController.php

@@ -4,6 +4,7 @@ namespace ghs\controllers;
 
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\classes\DistClass;
+use bizGhs\order\classes\OrderClass;
 use bizGhs\shop\classes\ShopClass;
 use common\components\util;
 use Yii;
@@ -33,6 +34,8 @@ class DistController extends BaseController
         }
         $custom->distId = $id;
         $custom->save();
+        // 客户片区变更后,同步更新该客户所有订单的片区(走 customId 单索引)
+        OrderClass::updateByCondition(['customId' => $customId], ['customDistId' => $id]);
         util::complete('修改成功');
     }
 

+ 8 - 0
app-ghs/controllers/OrderController.php

@@ -1005,6 +1005,14 @@ class OrderController extends BaseController
         if (isset($get['customId']) && !empty($get['customId'])) {
             $where['customId'] = $get['customId'];
         }
+        $customDistId = $get['customDistId'] ?? ($get['distId'] ?? 0);
+        if (!empty($customDistId)) {
+            $where['customDistId'] = (int)$customDistId;
+        }
+        $debt = isset($get['debt']) && is_numeric($get['debt']) ? (int)$get['debt'] : -1;
+        if ($debt > -1) {
+            $where['debt'] = $debt;
+        }
         if (isset($get['ids']) && !empty($get['ids'])) {
             $stringIds = $get['ids'];
             $newIds = explode(',', $stringIds);

+ 20 - 0
app-ghs/controllers/ShopController.php

@@ -259,6 +259,26 @@ class ShopController extends BaseController
         util::success(['shopImg' => $shopImg, 'smallShopImg' => $smallShopImg], '门店头像更新成功');
     }
 
+    //修改门店营业时间
+    public function actionUpdateOpenTime()
+    {
+        $post = Yii::$app->request->post();
+        $shopId = intval($post['shopId'] ?? $post['id'] ?? 0);
+        if ($shopId <= 0) {
+            $shopId = intval($this->shopId);
+        }
+        if ($shopId != intval($this->shopId)) {
+            util::fail('不是您的门店');
+        }
+        $shop = ShopClass::getById($shopId);
+        if (empty($shop)) {
+            util::fail('门店不存在');
+        }
+        \biz\shop\classes\ShopClass::valid($shop, $this->sjId);
+        \biz\shop\classes\ShopClass::updateOpenTime($shop, $post);
+        util::complete('修改成功');
+    }
+
     //添加门店 ssh 2021.1.14
     public function actionAdd()
     {

+ 3 - 2
app-ghs/controllers/TestController.php

@@ -495,7 +495,8 @@ class TestController extends BaseController
             //['name' => '惠达', 'merchantNo' => '8225810599201RH', 'wx' => [889521902, 889520798], 'zfb' => '2088580471883271'],
             //['name' => '广州花粉工坊', 'merchantNo' => '8225810599201RY', 'wx' => [892145716, 892145723], 'zfb' => '2088580818465548'],
             //['name' => '张家口小武鲜花批发', 'merchantNo' => '82213805992007R', 'wx' => [894997028, 894996929], 'zfb' => '2088680439799041'],
-            ['name' => '淮北花述语鲜花批发', 'merchantNo' => '82236605992001E', 'wx' => [895627520, 895627914], 'zfb' => '2088680541422679'],
+            //['name' => '淮北花述语鲜花批发', 'merchantNo' => '82236605992001E', 'wx' => [895627520, 895627914], 'zfb' => '2088680541422679'],
+            ['name' => '泉州馨喜鲜花批发', 'merchantNo' => '8223970599200KD', 'wx' => [896099124, 896098673], 'zfb' => '2088680670320387'],
             //['name' => '厦门纯彩花艺', 'merchantNo' => '8223930599200LD', 'wx' => [894984230, 894983290], 'zfb' => '2088680439152343'],
             //['name' => '东莞我要花鲜花', 'merchantNo' => '8226020599200R8', 'wx' => [894794554, 894794917], 'zfb' => '2088680405463378'],
             //['name' => '镇江花珩鲜花批发', 'merchantNo' => '82231405992003N', 'wx' => [894925711, 894925626], 'zfb' => '2088680426877183'],
@@ -1557,4 +1558,4 @@ class TestController extends BaseController
 
     }
 
-}
+}

+ 20 - 0
app-hd/controllers/ShopController.php

@@ -180,6 +180,26 @@ class ShopController extends BaseController
         }
     }
 
+    //修改门店营业时间
+    public function actionUpdateOpenTime()
+    {
+        $post = Yii::$app->request->post();
+        $shopId = intval($post['shopId'] ?? $post['id'] ?? 0);
+        if ($shopId <= 0) {
+            $shopId = intval($this->shopId);
+        }
+        if ($shopId != intval($this->shopId)) {
+            util::fail('不是您的门店');
+        }
+        $shop = ShopClass::getShopInfo($shopId);
+        if (empty($shop)) {
+            util::fail('门店不存在');
+        }
+        ShopClass::valid($shop, $this->sjId);
+        ShopClass::updateOpenTime($shop, $post);
+        util::complete('修改成功');
+    }
+
     public function actionAdd()
     {
         $data = Yii::$app->request->post();

+ 7 - 2
biz-ghs/clear/classes/ClearClass.php

@@ -314,9 +314,14 @@ class ClearClass extends BaseClass
         $deadline = $info['deadline'] ?? '';
         $deadTime = strtotime($deadline);
         $current = time();
-        if ($current >= $deadTime) {
+        // 仅待结清且已过期时才取消,避免已结清账单被误改状态
+        if ($current >= $deadTime && ($info['status'] ?? 0) == PurchaseClearClass::STATUS_AWAIT_PAY) {
+            $n = date("Y-m-d H:i:s");
             $info['status'] = PurchaseClearClass::STATUS_EXPIRE;
-            self::updateById($id, ['status' => PurchaseClearClass::STATUS_EXPIRE]);
+            self::updateById($id, [
+                'status' => PurchaseClearClass::STATUS_EXPIRE,
+                'remark' => "账单过期,已自动取消,参数:{$deadline} {$n}",
+            ]);
         }
 
         $purchaseIds = $info['purchaseIds'] ?? [];

+ 24 - 3
biz-ghs/order/classes/OrderClass.php

@@ -822,6 +822,8 @@ class OrderClass extends BaseClass
         $mainId = $data['mainId'] ?? 0;
         $ghsId = $data['ghsId'] ?? 0;
         $customId = $data['customId'] ?? 0;
+		$distId = $custom['distId'] ?? 0;
+		$data['customDistId'] = $distId;
         $snData = ['shopId' => $shopId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'customId' => $customId];
         $orderSn = orderSn::getGhsOrderSn($snData);
 
@@ -1410,8 +1412,18 @@ class OrderClass extends BaseClass
         $data['totalTkPrice'] = 0;
 
         if (!empty($data['list'])) {
+            $distIds = array_unique(array_filter(array_column($data['list'], 'customDistId')));
+            $distMap = [];
+            if (!empty($distIds)) {
+                $distMap = DistClass::getByIds($distIds, null, 'id');
+            }
             foreach ($data['list'] as $key => $val) {
 
+                $customDistId = intval($val['customDistId'] ?? 0);
+                $data['list'][$key]['customDistName'] = $customDistId > 0 && isset($distMap[$customDistId])
+                    ? ($distMap[$customDistId]['name'] ?? '')
+                    : '';
+
                 //同个人同地址当天订单数
                 $sameNum = $val['mergeNum'];
                 if ($sameNum > 0) {
@@ -3045,7 +3057,7 @@ XL;
         /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
         $orderMainId = $order->mainId;
         if (getenv('YII_ENV') == 'production') {
-            $map = [65726, 58, 25119, 28500, 1294, 12925, 2644,10652,2084];
+            $map = [65726, 58, 25119, 28500, 1294, 12925, 2644,10652,2084,89473];
         } else {
             $map = [828];
         }
@@ -3070,7 +3082,7 @@ XL;
             }
         }
         //东莞我要花 福州福清我要花 手机后四号变星号
-        if (in_array((int)$orderMainId, [25119, 2644,10652,2084], true)) {
+        if (in_array((int)$orderMainId, [25119, 2644,10652,2084,89473], true)) {
             $customMobile = preg_replace('/(.{4})$/u', '****', trim($customMobile));
         }
         $customName = $order->customName ?? '';
@@ -3142,12 +3154,21 @@ XL;
             $payTime = $order->payTime ?? '';
             $payDate = date('m-d H:i', strtotime($payTime));
             $content = '<TEXT x="400" y="30" font="12" w="3" h="3" r="90">' . $customName . '</TEXT>';
-            $content .= '<TEXT x="280" y="30" font="12" w="2" h="2" r="90">' . $fullAddress . '</TEXT>';
+            
+            // 地址超过15个字,字体大小(w和h)变小一级(由 w="2" h="2" 变为 w="1" h="1")
+            $addressLen = mb_strlen($fullAddress, 'UTF-8');
+            $fontScale = $addressLen > 16 ? '1' : '2';
+            $content .= '<TEXT x="280" y="30" font="12" w="' . $fontScale . '" h="' . $fontScale . '" r="90">' . $fullAddress . '</TEXT>';
+            
             $content .= '<TEXT x="180" y="30" font="12" w="2" h="2" r="90">' . $customMobile . '  ' . $itemNum . '扎</TEXT>';
             $content .= '<TEXT x="86" y="30" font="12" w="2" h="2" r="90">' . $distName . ' ' . $payDate . '</TEXT>';
             /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
         }
         $p->printLabelMsg($content);
+        if (is_object($order) && method_exists($order, 'save')) {
+            $order->printWlNum = intval($order->printWlNum ?? 0) + 1;
+            $order->save();
+        }
         return true;
     }
 

+ 32 - 0
biz/shop/classes/ShopClass.php

@@ -79,6 +79,38 @@ class ShopClass extends BaseClass
         return 0;
     }
 
+    //修改门店营业时间
+    public static function updateOpenTime($shop, $data)
+    {
+        $id = $shop['id'] ?? 0;
+        if ($id <= 0) {
+            util::fail('门店不存在');
+        }
+        $open = isset($data['open']) ? intval($data['open']) : 1;
+        if (!in_array($open, [0, 1], true)) {
+            util::fail('营业状态无效');
+        }
+        $openType = isset($data['openType']) ? intval($data['openType']) : 0;
+        $openStartTime = trim($data['openStartTime'] ?? '');
+        $openEndTime = trim($data['openEndTime'] ?? '');
+        if ($openType == 0) {
+            $openStartTime = '';
+            $openEndTime = '';
+        } else {
+            if ($openStartTime === '' || $openEndTime === '') {
+                util::fail('请填写营业时间');
+            }
+            if (!preg_match('/^\d{2}:\d{2}$/', $openStartTime) || !preg_match('/^\d{2}:\d{2}$/', $openEndTime)) {
+                util::fail('营业时间格式错误');
+            }
+        }
+        return self::updateById($id, [
+            'open' => $open,
+            'openStartTime' => $openStartTime,
+            'openEndTime' => $openEndTime,
+        ]);
+    }
+
     //获取图片信息 ssh 2021.3.14
     public static function getShopInfo($id)
     {

+ 220 - 0
console/controllers/CustomDistController.php

@@ -0,0 +1,220 @@
+<?php
+
+namespace console\controllers;
+
+use biz\shop\classes\ShopClass;
+use bizGhs\custom\models\Custom;
+use bizGhs\order\classes\OrderClass;
+use bizGhs\order\models\Order;
+use common\components\dict;
+use Yii;
+use yii\console\Controller;
+use yii\console\ExitCode;
+
+/**
+ * 按 mainId 补更新 xhGhsOrder.customDistId
+ *
+ * 流程:
+ * 1. 查出 mainId 下所有门店
+ * 2. 查出各门店客户及 distId
+ * 3. 更新该门店、该客户订单的 customDistId
+ *
+ * 用法:
+ *   php yii custom-dist/fill-ghs-order
+ *   php yii custom-dist/fill-ghs-order --dryRun=1
+ *   php yii custom-dist/fill-ghs-order --batchSize=200 --sleepMs=100
+ *
+ * mainId 在下方 $fillMainIds 中配置。
+ */
+class CustomDistController extends Controller
+{
+    /**
+     * 需要补更新 customDistId 的 mainId 列表(在此填写)
+     * @var int[]
+     */
+    private static $fillMainIds = [
+        25119, 2644,10652,2084,89473,50
+    ];
+
+    /** @var int 每批处理的客户数 */
+    public $batchSize = 200;
+
+    /** @var int 每批之间的休眠毫秒数 */
+    public $sleepMs = 100;
+
+    /** @var int 是否仅预览,1=是 */
+    public $dryRun = 0;
+
+    /** @var int 是否强制全部覆盖,1=是(默认只修不一致的) */
+    public $all = 0;
+
+    /** @var int 每个 mainId 最多更新订单条数,0=不限制 */
+    public $limit = 0;
+
+    public function options($actionID)
+    {
+        return array_merge(parent::options($actionID), [
+            'batchSize',
+            'sleepMs',
+            'dryRun',
+            'all',
+            'limit',
+        ]);
+    }
+
+    public function actionFillGhsOrder()
+    {
+        ini_set('memory_limit', '512M');
+        set_time_limit(0);
+
+        $mainIdList = array_values(array_unique(array_filter(array_map('intval', self::$fillMainIds))));
+        if (empty($mainIdList)) {
+            $this->stderr("请在 CustomDistController::\$fillMainIds 中配置 mainId\n");
+            return ExitCode::UNSPECIFIED_ERROR;
+        }
+        if ($this->batchSize < 1) {
+            $this->stderr("batchSize 必须大于 0\n");
+            return ExitCode::UNSPECIFIED_ERROR;
+        }
+
+        $this->stdout(sprintf(
+            "开始补更新 %s.customDistId,mainIds: %s,batchSize: %d,dryRun: %d,all: %d\n",
+            Order::tableName(),
+            implode(',', $mainIdList),
+            $this->batchSize,
+            (int)$this->dryRun,
+            (int)$this->all
+        ));
+
+        $totalUpdated = 0;
+        foreach ($mainIdList as $mainId) {
+            $updated = $this->fillMainId((int)$mainId);
+            $totalUpdated += $updated;
+            $this->stdout("mainId={$mainId} 完成,更新订单 {$updated} 条\n");
+        }
+
+        $this->stdout("全部完成,合计更新订单 {$totalUpdated} 条\n");
+        return ExitCode::OK;
+    }
+
+    private function fillMainId($mainId)
+    {
+        $ghsPtStyle = dict::getDict('ptStyle', 'ghs');
+        $shopList = ShopClass::getAllByCondition(
+            ['mainId' => $mainId, 'ptStyle' => $ghsPtStyle],
+            null,
+            'id,shopName',
+            null,
+            true
+        );
+        if (empty($shopList)) {
+            $this->stdout("mainId={$mainId} 没有找到门店,跳过\n");
+            return 0;
+        }
+
+        $updated = 0;
+        foreach ($shopList as $shop) {
+            if ($this->limit > 0 && $updated >= $this->limit) {
+                break;
+            }
+            $shopId = (int)($shop->id ?? 0);
+            if ($shopId <= 0) {
+                continue;
+            }
+            $shopName = $shop->shopName ?? '';
+            $this->stdout("mainId={$mainId} shopId={$shopId} {$shopName} 开始处理客户\n");
+
+            $shopUpdated = $this->fillShop($mainId, $shopId, $updated);
+            $updated += $shopUpdated;
+            $this->stdout("mainId={$mainId} shopId={$shopId} 更新订单 {$shopUpdated} 条\n");
+        }
+
+        return $updated;
+    }
+
+    private function fillShop($mainId, $shopId, $mainUpdated)
+    {
+        $updated = 0;
+        $query = new \yii\db\Query();
+        $query->from(Custom::tableName());
+        $query->where(['ownShopId' => $shopId]);
+        $query->orderBy('id asc');
+
+        foreach ($query->batch($this->batchSize) as $customerList) {
+            if ($this->limit > 0 && ($mainUpdated + $updated) >= $this->limit) {
+                break;
+            }
+            if (empty($customerList)) {
+                continue;
+            }
+
+            foreach ($customerList as $custom) {
+                $customId = (int)($custom['id'] ?? 0);
+                $distId = (int)($custom['distId'] ?? 0);
+                if ($customId <= 0) {
+                    continue;
+                }
+
+                $countWhere = $this->buildOrderCountWhere($mainId, $shopId, $customId, $distId);
+                $updateWhere = $this->buildOrderUpdateWhere($mainId, $shopId, $customId, $distId);
+
+                if ($this->dryRun) {
+                    $count = (int)OrderClass::getCount($countWhere);
+                    if ($count > 0) {
+                        $customName = $custom['name'] ?? '';
+                        $this->stdout("[dryRun] mainId={$mainId} shopId={$shopId} customId={$customId} {$customName} distId={$distId} 订单 {$count} 条\n");
+                        $updated += $count;
+                    }
+                    continue;
+                }
+
+                $affected = Order::updateAll(['customDistId' => $distId], $updateWhere);
+                if ($affected > 0) {
+                    $updated += (int)$affected;
+                }
+
+                if ($this->limit > 0 && ($mainUpdated + $updated) >= $this->limit) {
+                    break 2;
+                }
+            }
+
+            if ($this->sleepMs > 0) {
+                usleep($this->sleepMs * 1000);
+            }
+        }
+
+        return $updated;
+    }
+
+    /**
+     * updateAll 用的 Yii 标准条件
+     */
+    private function buildOrderUpdateWhere($mainId, $shopId, $customId, $distId)
+    {
+        $base = [
+            'mainId' => $mainId,
+            'shopId' => $shopId,
+            'customId' => $customId,
+        ];
+        if ($this->all) {
+            return $base;
+        }
+        return ['and', $base, ['!=', 'customDistId', $distId]];
+    }
+
+    /**
+     * conditionQuery 用的等值/不等条件(仅 dryRun 统计)
+     */
+    private function buildOrderCountWhere($mainId, $shopId, $customId, $distId)
+    {
+        $where = [
+            'mainId' => $mainId,
+            'shopId' => $shopId,
+            'customId' => $customId,
+        ];
+        if (!$this->all) {
+            $where['customDistId!='] = $distId;
+        }
+        return $where;
+    }
+}