Procházet zdrojové kódy

修改种植、销售

Your Name před 5 roky
rodič
revize
83e79b4c77
3 změnil soubory, kde provedl 72 přidání a 5 odebrání
  1. 2 0
      apps/AppInfo/models.py
  2. 3 1
      apps/Equipment/urls.py
  3. 67 4
      apps/Equipment/views.py

+ 2 - 0
apps/AppInfo/models.py

@@ -509,6 +509,7 @@ class Sell_Manage(models.Model):
     num = models.CharField(u'数量', max_length=20, blank=True, null=True)
     money = models.CharField(u'金额', max_length=20, blank=True, null=True)
     upl_time = models.DateTimeField(u'创建时间', blank=True, null=True)
+    sell_img = models.CharField(u'销售图片', max_length=200, blank=True, null=True)
 
     class Meta:
         verbose_name = '销售管理'
@@ -543,6 +544,7 @@ class Areacrop(models.Model):
     crop_count = models.CharField(u'作物数量', max_length=20, blank=True, null=True)
     upl_time = models.DateTimeField(u'种植时间', blank=True, null=True)
     end_time = models.DateTimeField(u'结束时间', blank=True, null=True)
+    crop_img = models.CharField(u'作物图片', max_length=200, blank=True, null=True)
 
     class Meta:
         verbose_name = '区域作物表'

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 3 - 1
apps/Equipment/urls.py


+ 67 - 4
apps/Equipment/views.py

@@ -2443,6 +2443,33 @@ class Sell_Land(ListView):
         return HttpResponse(data)
 
 
+#销售图片
+class Sell_Photo(ListView):
+    def post(self,request):
+        gar_photo = request.FILES.get('gar_img')
+        if gar_photo:
+            print("视频图片:", gar_photo)
+            garden_photo_dir = 'sell_photo/'
+            end_name = gar_photo.name.split('.')[-1]
+            # 判断如果路径不存在,即创建路径
+            if os.path.exists(garden_photo_dir) == False:
+                os.makedirs(garden_photo_dir)
+            img = Image.open(gar_photo)
+            now_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
+            pic_name = now_time + '.' + end_name
+            print("pic_name:", pic_name)
+            img.save(garden_photo_dir + pic_name)
+            gar_photo = garden_photo_dir + pic_name
+            print("gar_photo:",gar_photo)
+            data = {"code": 0,"msg": "","data": {"src": gar_photo}}
+        else:
+            pro_photo = "0"
+            data = {"code": 404,"msg": "","data": {"src": gar_photo}}
+        data = json.dumps(data)
+        return HttpResponse(data)
+
+
+
 #  销售管理
 class Sell_View(ListView):
     def get(self,request):
@@ -2472,7 +2499,8 @@ class Sell_View(ListView):
                         "id":x.id,
                         "farm":x.farm.name,"name":x.name,
                         "num":x.num,"money":x.money,
-                        "time":x.upl_time.strftime('%Y-%m-%d')
+                        "time":x.upl_time.strftime('%Y-%m-%d'),
+                        "sell_img":x.sell_img
                     })
         except Exception as e:
             print(e)
@@ -2495,6 +2523,7 @@ class Sell_New(ListView):
         money = request.POST.get("money")
         time = request.POST.get("time")
         s_id = request.POST.get("id")
+        sell_img = request.POST.get("sell_img")
         username = request.user.id
         
         if s_id:
@@ -2506,6 +2535,7 @@ class Sell_New(ListView):
                 sell_obj.num = num
                 sell_obj.money = money
                 sell_obj.upl_time = time
+                sell_obj.sell_img = sell_img
                 sell_obj.save()
                 data = "1"
             except Exception as e:
@@ -2514,7 +2544,7 @@ class Sell_New(ListView):
         else:
             try:
                 farm_obj = FarmList.objects.get(name=farm,user=username)
-                Sell_Manage.objects.create(farm=farm_obj,name=name,num=num,money=money,upl_time=time)
+                Sell_Manage.objects.create(farm=farm_obj,name=name,num=num,money=money,upl_time=time,sell_img=sell_img)
                 data = "1"
             except Exception as e:
                 print(e)
@@ -2574,6 +2604,7 @@ class CropCount(ListView):
         upl_time = request.POST.get("upl_time")
         cropname = request.POST.get('cropname')
         city = request.POST.get("city")
+        crop_img = request.POST.get("crop_img")
         count=crop_count + city
         print(count)
         #修改
@@ -2586,6 +2617,7 @@ class CropCount(ListView):
                     area=crops,
                     upl_time=upl_time,
                     crop_count=count,
+                    crop_img=crop_img,
                 )
                 data = "1"
             except Exception as e:
@@ -2601,6 +2633,7 @@ class CropCount(ListView):
                     area=crops,
                     upl_time=upl_time,
                     crop_count=count,
+                    crop_img=crop_img,
                 )
                 data = "1"
             except Exception as e:
@@ -2610,6 +2643,33 @@ class CropCount(ListView):
 
 
 
+#种植管理
+class CropCount_Photo(ListView):
+    def get(self,request):
+        pass
+    def post(self,request):
+        gar_photo = request.FILES.get('gar_img')
+        if gar_photo:
+            print("视频图片:", gar_photo)
+            garden_photo_dir = 'cropcount_photo/'
+            end_name = gar_photo.name.split('.')[-1]
+            # 判断如果路径不存在,即创建路径
+            if os.path.exists(garden_photo_dir) == False:
+                os.makedirs(garden_photo_dir)
+            img = Image.open(gar_photo)
+            now_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
+            pic_name = now_time + '.' + end_name
+            print("pic_name:", pic_name)
+            img.save(garden_photo_dir + pic_name)
+            gar_photo = garden_photo_dir + pic_name
+            print("gar_photo:",gar_photo)
+            data = {"code": 0,"msg": "","data": {"src": gar_photo}}
+        else:
+            pro_photo = "0"
+            data = {"code": 404,"msg": "","data": {"src": gar_photo}}
+        data = json.dumps(data)
+        return HttpResponse(data)
+
 
 # 种植管理
 class CropCount_View(ListView):
@@ -2636,7 +2696,8 @@ class CropCount_View(ListView):
                         "img":x.area.farm_img,
                         "time":data,
                         "id":x.id,
-                        "upl_time":x.upl_time.strftime('%Y-%m-%d')
+                        "upl_time":x.upl_time.strftime('%Y-%m-%d'),
+                        "crop_img":x.crop_img,
                         } 
                     dat.append({"data":h2,"curro":curro})
         nums = len(dat)
@@ -2663,7 +2724,9 @@ class CropCount_View(ListView):
                     "area":i.area.name,
                     "crop_count":i.crop_count,
                     "cropname":i.cropname,
-                    "upl_time":i.upl_time.strftime('%Y-%m-%d')
+                    "upl_time":i.upl_time.strftime('%Y-%m-%d'),
+                    "crop_img":i.crop_img,
+
                 })
         #删除
         elif req == "del":