ソースを参照

update status状态不会续费

chenjunkai 6 年 前
コミット
feba81f911
1 ファイル変更16 行追加17 行削除
  1. 16 17
      Controller/DeviceMeal.py

+ 16 - 17
Controller/DeviceMeal.py

@@ -164,28 +164,27 @@ class DeviceMeal(View):
         if param_flag is True:
         if param_flag is True:
             try:
             try:
                 store_meal = Store_Meal.objects.get(id=rank)
                 store_meal = Store_Meal.objects.get(id=rank)
-                device_meal = Device_Meal.objects.get(id=id)
-                # days = store_meal.day
-                # now_time = timezone.localtime(timezone.now())
-                # if now_time > device_meal.end_time:
-                #     end_time = now_time + datetime.timedelta(days=int(days))
-                # else:
-                #     end_time = device_meal.end_time + datetime.timedelta(days=int(days))
+                dmqs = Device_Meal.objects.get(id=id)
+                if rank != dmqs.rank_id:
+                    days = store_meal.day
+                    now_time = timezone.localtime(timezone.now())
+                    if now_time > dmqs.end_time:
+                        end_time = now_time + datetime.timedelta(days=int(days))
+                    else:
+                        end_time = dmqs.end_time + datetime.timedelta(days=int(days))
+                    dmqs.end_time = end_time
+                dmqs.status = status
+                dmqs.uid = uid
+                dmqs.channel = channel
+                dmqs.rank = store_meal
+                dmqs.save()
             except Exception as e:
             except Exception as e:
                 errorInfo = traceback.format_exc()
                 errorInfo = traceback.format_exc()
                 print(errorInfo)
                 print(errorInfo)
                 return response.json(424, {'details': repr(e)})
                 return response.json(424, {'details': repr(e)})
             else:
             else:
-                if device_meal.id:
-                    device_meal.status = status
-                    device_meal.uid = uid
-                    device_meal.channel = channel
-                    # device_meal.end_time = end_time
-                    device_meal.rank = store_meal
-                    device_meal.save()
-                    return response.json(0, {'update_id': device_meal.id,
-                                             'update_time': str(device_meal.now_time),
-                                             'end_time': str(device_meal.end_time)})
+                return response.json(0, {'update_id': dmqs.id,'update_time': str(dmqs.now_time),
+                                             'end_time': str(dmqs.end_time)})
         else:
         else:
             return response.json(444)
             return response.json(444)