shish 1 month ago
parent
commit
a4518a864b
2 changed files with 49 additions and 0 deletions
  1. 13 0
      app-ghs/controllers/ShMethodController.php
  2. 36 0
      biz-ghs/order/classes/ShMethodClass.php

+ 13 - 0
app-ghs/controllers/ShMethodController.php

@@ -29,6 +29,19 @@ class ShMethodController extends BaseController
         }
     }
 
+    /**
+     * 获取所有配送方式的排序和别名信息
+     */
+    public function actionGetSorts()
+    {
+        try {
+            $sorts = ShMethodClass::getSorts($this->shopId, $this->mainId);
+            util::success($sorts);
+        } catch (\Exception $e) {
+            util::fail($e->getMessage());
+        }
+    }
+
     /**
      * 保存指定配送方式的配置
      * POST 参数:

+ 36 - 0
biz-ghs/order/classes/ShMethodClass.php

@@ -14,6 +14,42 @@ class ShMethodClass extends BaseClass
 {
     public static $baseFile = '\bizGhs\order\models\ShMethod';
 
+    /**
+     * 获取所有配送方式的排序和别名信息
+     * @param int $shopId 门店ID
+     * @param int $mainId 商户ID
+     * @return array
+     */
+    public static function getSorts($shopId, $mainId)
+    {
+        $list = [];
+        $aliases = [
+            0 => '送货',
+            1 => '自取',
+            2 => '跑腿',
+            3 => '快递',
+            4 => '物流'
+        ];
+        for ($style = 0; $style <= 4; $style++) {
+            $config = self::getByCondition(['shopId' => $shopId, 'style' => $style]);
+            $sort = 0;
+            $alias = $aliases[$style];
+            $status = 1;
+            if (!empty($config)) {
+                $sort = isset($config['sort']) ? (int)$config['sort'] : 0;
+                $alias = !empty($config['alias']) ? $config['alias'] : $aliases[$style];
+                $status = isset($config['status']) ? (int)$config['status'] : 1;
+            }
+            $list[] = [
+                'style' => $style,
+                'name' => $alias,
+                'sort' => $sort,
+                'status' => $status
+            ];
+        }
+        return $list;
+    }
+
     /**
      * 获取指定门店和类型的配送方式配置,若不存在则进行默认初始化
      * @param int $shopId 门店ID