瀏覽代碼

用户选取壁纸 - 首次选择壁纸创建壁纸

linhaohong 1 年之前
父節點
當前提交
a88e970bee
共有 1 個文件被更改,包括 25 次插入9 次删除
  1. 25 9
      Controller/UserDevice/UserDeviceShareController.py

+ 25 - 9
Controller/UserDevice/UserDeviceShareController.py

@@ -237,7 +237,7 @@ class UserDeviceShareView(View):
             # 查询用户选中的壁纸
             user_checked_qs = DeviceWallpaper.objects.filter(channel=channel, uid=uid,
                                                              device_type=device_type, parent_id__gt=0, status=1)
-            checked_id = user_checked_qs[0].parent_id if user_checked_qs.exists() else 0
+            checked_id = user_checked_qs[0].parent_id if user_checked_qs.exists() else def_wallpaper_qs.first().id
 
             wallpaper_list = []
             if def_wallpaper_qs.exists() or user_wallpaper_qs.exists():
@@ -437,17 +437,33 @@ class UserDeviceShareView(View):
             uid = request_dict.get('uid', None)
             if not all([wallpaper_id, uid]):
                 return response.json(444)
-            device_wallpaper = DeviceWallpaper.objects.filter(id=wallpaper_id).values("storage_type", "obj_prefix",
+            device_wallpaper = DeviceWallpaper.objects.filter(id=wallpaper_id).values("device_type", "storage_type",
+                                                                                      "obj_prefix",
                                                                                       "obj_name",
                                                                                       "classification",
                                                                                       "channel").first()
-            DeviceWallpaper.objects.filter(uid=uid, parent_id__gt=0).update(
-                storage_type=device_wallpaper["storage_type"],
-                classification=device_wallpaper["classification"],
-                obj_prefix=device_wallpaper["obj_prefix"],
-                obj_name=device_wallpaper["obj_name"],
-                parent_id=wallpaper_id
-            )
+            device_wallpaper_qs = DeviceWallpaper.objects.filter(uid=uid, parent_id__gt=0)
+            if device_wallpaper_qs.exists():
+                device_wallpaper_qs.update(
+                    storage_type=device_wallpaper["storage_type"],
+                    classification=device_wallpaper["classification"],
+                    obj_prefix=device_wallpaper["obj_prefix"],
+                    obj_name=device_wallpaper["obj_name"],
+                    parent_id=wallpaper_id
+                )
+            else:
+                DeviceWallpaper.objects.create(
+                    device_type=device_wallpaper["device_type"],
+                    storage_type=device_wallpaper["storage_type"],
+                    obj_name=device_wallpaper["obj_name"],
+                    obj_prefix=device_wallpaper["obj_prefix"],
+                    classification=device_wallpaper["classification"],
+                    uid=uid,
+                    channel=device_wallpaper["channel"],
+                    status=1,
+                    parent_id=wallpaper_id,
+                    create_time=int(time.time())
+                )
             return response.json(0)
         except Exception as e:
             LOGGER.error('用户选取壁纸异常:errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))