WIN-2308041133\Administrator 3 ماه پیش
والد
کامیت
1114e3eb17

+ 16 - 0
app/api/controller/v1/admin/StoreOrderController.php

@@ -757,6 +757,7 @@ class StoreOrderController
         $uid = $request->uid();
         $data = $request->postMore([
             ['id', 0],
+            ['store_id', 0],
             ['name', ''],
             ['introduction', ''],
             ['image', ''],
@@ -825,6 +826,21 @@ class StoreOrderController
             return app('json')->success(100014);
         }
 
+        // 验证store_id
+        $storeId = $data['store_id'];
+        if ($storeId > 0) {
+            // 编辑门店申请,验证门店是否存在且属于该用户
+            $storeInfo = \app\services\system\store\SystemStoreServices::class;
+            $storeServices = app()->make($storeInfo);
+            $store = $storeServices->get($storeId);
+            if (!$store) {
+                return app('json')->fail('门店不存在');
+            }
+            if ($store['uid'] != $uid) {
+                return app('json')->fail('无权编辑他人门店');
+            }
+        }
+
         // 保存门店申请记录
         $data['add_time'] = time();
         $recordServices->save($data);

+ 3 - 3
app/dao/system/store/SystemStoreRecordDao.php

@@ -42,12 +42,12 @@ class SystemStoreRecordDao extends BaseDao
      */
     public function getApplyList(array $where, int $page = 0, int $limit = 0)
     {
-        $query = $this->search($where)->with(['user']);
-        
+        $query = $this->search($where)->with(['user', 'store']);
+
         if ($page && $limit) {
             $query->page($page, $limit);
         }
-        
+
         return $query->order('id desc')->select()->toArray();
     }
 

+ 9 - 0
app/model/system/store/SystemStoreRecord.php

@@ -68,4 +68,13 @@ class SystemStoreRecord extends Model
     {
         return $this->belongsTo(\app\model\user\User::class, 'uid', 'uid')->field('uid,nickname,avatar,phone');
     }
+
+    /**
+     * 关联门店表
+     * @return \think\model\relation\BelongsTo
+     */
+    public function store()
+    {
+        return $this->belongsTo(SystemStore::class, 'store_id', 'id')->field('id,name,phone,address');
+    }
 }

+ 62 - 40
app/services/system/store/SystemStoreRecordServices.php

@@ -85,49 +85,71 @@ class SystemStoreRecordServices extends BaseServices
                 throw new AdminException('审核失败');
             }
 
-            // 创建正式门店记录
-            $storeServices = app()->make(SystemStoreServices::class);
-            $storeData = [
-                'name' => $recordInfo['name'],
-                'phone' => $recordInfo['phone'],
-                'address' => $recordInfo['address'],
-                'detailed_address' => $recordInfo['detailed_address'],
-                'latlng' => $recordInfo['latlng'],
-                'latitude' => $recordInfo['latitude'],
-                'longitude' => $recordInfo['longitude'],
-                'day_time' => $recordInfo['day_time'],
-                'valid_time' => $recordInfo['valid_time'],
-                'image' => $recordInfo['image'],
-                'uid' => $recordInfo['uid'],
-                'is_show' => 1,
-                'add_time' => time(),
-            ];
-            $storeId = $storeServices->save($storeData);
-
-            if (!$storeId) {
-                throw new AdminException('创建门店失败');
-            }
-
-            // 添加用户为店员
-            $staffServices = app()->make(SystemStoreStaffServices::class);
-            $userServices = app()->make(\app\services\user\UserServices::class);
-
-            // 检查该用户是否已经是店员
-            if (!$staffServices->count(['uid' => $recordInfo['uid']])) {
-                // 从user表获取店员的image和staff_name
-                $userInfo = $userServices->getUserInfo($recordInfo['uid']);
-
-                $staffData = [
-                    'uid' => $recordInfo['uid'],
-                    'store_id' => $storeId,
-                    'staff_name' => $userInfo['nickname'] ?? '',
-                    'avatar' => $userInfo['avatar'] ?? ($userInfo['image'] ?? ''),
+            // 判断是新增门店还是编辑门店
+            if ($recordInfo['store_id'] > 0) {
+                // 编辑现有门店
+                $storeServices = app()->make(SystemStoreServices::class);
+                $storeData = [
+                    'name' => $recordInfo['name'],
+                    'phone' => $recordInfo['phone'],
+                    'address' => $recordInfo['address'],
+                    'detailed_address' => $recordInfo['detailed_address'],
+                    'latlng' => $recordInfo['latlng'],
+                    'latitude' => $recordInfo['latitude'],
+                    'longitude' => $recordInfo['longitude'],
+                    'day_time' => $recordInfo['day_time'],
+                    'valid_time' => $recordInfo['valid_time'],
+                    'image' => $recordInfo['image'],
+                ];
+                $updateRes = $storeServices->update($recordInfo['store_id'], $storeData);
+                if (!$updateRes) {
+                    throw new AdminException('更新门店失败');
+                }
+            } else {
+                // 创建新门店
+                $storeServices = app()->make(SystemStoreServices::class);
+                $storeData = [
+                    'name' => $recordInfo['name'],
                     'phone' => $recordInfo['phone'],
-                    'verify_status' => 1,
-                    'status' => 1,
+                    'address' => $recordInfo['address'],
+                    'detailed_address' => $recordInfo['detailed_address'],
+                    'latlng' => $recordInfo['latlng'],
+                    'latitude' => $recordInfo['latitude'],
+                    'longitude' => $recordInfo['longitude'],
+                    'day_time' => $recordInfo['day_time'],
+                    'valid_time' => $recordInfo['valid_time'],
+                    'image' => $recordInfo['image'],
+                    'uid' => $recordInfo['uid'],
+                    'is_show' => 1,
                     'add_time' => time(),
                 ];
-                $staffServices->save($staffData);
+                $storeId = $storeServices->save($storeData);
+
+                if (!$storeId) {
+                    throw new AdminException('创建门店失败');
+                }
+
+                // 添加用户为店员
+                $staffServices = app()->make(SystemStoreStaffServices::class);
+                $userServices = app()->make(\app\services\user\UserServices::class);
+
+                // 检查该用户是否已经是店员
+                if (!$staffServices->count(['uid' => $recordInfo['uid']])) {
+                    // 从user表获取店员的image和staff_name
+                    $userInfo = $userServices->getUserInfo($recordInfo['uid']);
+
+                    $staffData = [
+                        'uid' => $recordInfo['uid'],
+                        'store_id' => $storeId,
+                        'staff_name' => $userInfo['nickname'] ?? '',
+                        'avatar' => $userInfo['avatar'] ?? ($userInfo['image'] ?? ''),
+                        'phone' => $recordInfo['phone'],
+                        'verify_status' => 1,
+                        'status' => 1,
+                        'add_time' => time(),
+                    ];
+                    $staffServices->save($staffData);
+                }
             }
 
             return true;