瀏覽代碼

营业时间

shish 2 月之前
父節點
當前提交
cc67422274
共有 2 個文件被更改,包括 52 次插入0 次删除
  1. 20 0
      app-ghs/controllers/ShopController.php
  2. 32 0
      biz/shop/classes/ShopClass.php

+ 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()
     {

+ 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)
     {