|
|
@@ -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;
|