rabin 6 years ago
parent
commit
5be23ada4c

+ 1 - 1
admin/page/__load__.py

@@ -56,7 +56,7 @@ class Load(Base):
 		parent = [['农场与设备管理', '网站管理', '基础设置'],['', '', '']]
 		child = [
 			[['/farm/farm','/device/gateway','/device/info','/work/work','/work/category','/work/land','/origin/batch','/farm/user','/device/printer','/msg/msg'],['农场列表', '网关管理', '设备管理', '农场农事管理', '农场农事方式', '农场地块管理', '溯源批次管理','农场用户管理','农场打印机','消息提醒']]
-			,[['/web/set','/web/category','/web/article','/web/menu', 'sms/sms'],['网站资料设置', '文章分类', '发布内容文章', '菜单管理', '短信通知']]
+			,[['/web/set','/web/category','/web/article','/web/menu', 'sms/sms'],['首页内容管理', '文章分类', '发布内容文章', '菜单管理', '短信通知']]
 			,[['/device/type','/hardware/type','/msg/type','/admin/admin','/admin/role','/hardware/hardware', '/admin/log'],['设备类型管理','硬件类型管理', '消息类型设置', '管理员设置', '管理权限设置','硬件设备记录', '系统日志']]
 			]
 		return (parent,child)

+ 2 - 82
admin/page/web.py

@@ -13,8 +13,8 @@ class set_path(Load):
 	def get(self):
 		self.common(
 			path = '/web/set'
-			,label = (u'标题',u'子标题',u'关键词',u'描述',u'icp备案号',u'联系电话',u'微信管理')
-			,update = ('name-input-required','subname-input-required','keywords-input-required','description-input-required','icp-input-required','tel-input-required',u'mobile-pic--')
+			,label = (u'标题',u'子标题',u'关键词',u'描述',u'icp备案号',u'联系电话',u'视频地址',u'微信图片',u'微信文字',u'微信链接')
+			,update = ('name-input-required','subname-input-required','keywords-input-required','description-input-required','icp-input-required','tel-input-required',u'video-input-required',u'wx_pic-pic-required-',u'wx_text-editor-required',u'wx_link-input-required')
 		)
 		self.commonOne('web_set', id=1)
 		self.commonView('set')
@@ -104,86 +104,6 @@ class category_update_path(Load):
 	def delete(self):
 		self.commonDelete('web_article_category')
 
-class help_path(Load):
-	@Web.auth
-	@Web.setting
-	def get(self):
-		self.common(
-			name = u'帮助'
-			,path = '/web/help'
-			,width = '800'
-			,height = '600'
-			,search = (('label-1','cdate-time-start','cdate-time-end','category_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'帮助分类',u'帮助标题'))
-			,thead = (u'帮助标题', u'帮助分类', u'更新时间')
-			,tbody = ('name', 'category', 'cdate')
-			,state = True
-		)
-		self.data['common']['search_category_id-select-'] = self.service('common').list('web_help_category')
-		self.commonList('web_help')
-		if self.data['list']:
-			for key, value in enumerate(self.data['list']):
-				category = self.service('common').one('web_help_category', id=value['category_id'])
-				self.data['list'][key]['category'] = category['name']
-		self.commonView('list')
-
-class help_update_path(Load):
-	@Web.auth
-	@Web.setting
-	def get(self):
-		self.common(
-			path = '/web/help'
-			,label = (u'帮助标题',u'帮助分类',u'帮助内容')
-			,update = ('name-input-required','category_id-select-required',u'content-editor--请输入内容')
-			,update_category_id = self.service('common').list('web_help_category')
-		)
-		self.commonOne('web_help')
-		self.commonView('update')
-	@Web.auth
-	@Web.setting
-	def post(self):
-		self.commonUpdate('web_help')
-	@Web.auth
-	@Web.setting
-	def delete(self):
-		self.commonDelete('web_help')
-
-class help_category_path(Load):
-	@Web.auth
-	@Web.setting
-	def get(self):
-		self.common(
-			name = u'分类'
-			,path = '/web/help_category'
-			,width = '600'
-			,height = '300'
-			,search = (('label-1','cdate-time-start','cdate-time-end','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'分类名称'))
-			,thead = (u'帮助分类名称', u'更新时间')
-			,tbody = ('name', 'cdate')
-			,state = True
-		)
-		self.commonList('web_help_category')
-		self.commonView('list')
-
-class help_category_update_path(Load):
-	@Web.auth
-	@Web.setting
-	def get(self):
-		self.common(
-			path = '/web/help_category'
-			,label = (u'帮助分类名称',)
-			,update = ('name-input-required',)
-		)
-		self.commonOne('web_help_category')
-		self.commonView('update')
-	@Web.auth
-	@Web.setting
-	def post(self):
-		self.commonUpdate('web_help_category')
-	@Web.auth
-	@Web.setting
-	def delete(self):
-		self.commonDelete('web_help_category')
-
 class menu_path(Load):
 	@Web.auth
 	@Web.setting

+ 3 - 0
conf/dev.conf

@@ -59,11 +59,13 @@ top 				= farm
 [front]
 port				= 8088
 debug				= True
+xsrf_cookies		= False
 ;请求的buffersize
 max_buffer_size		= 210763776
 ;子进程
 process				= 0
 url					= http://192.168.15.10:8088/device
+qrcode				= http://pan.baidu.com/share/qrcode?w=300&h=300&url=
 
 ;网站前台配置
 [web]
@@ -72,6 +74,7 @@ debug				= True
 max_buffer_size		= 210763776
 process				= 0
 url					= http://192.168.15.10:8089/
+originurl			= http://192.168.15.10:8089/origin?id=
 
 ;微信小程序配置
 [weixinApp]

+ 18 - 1
conf/env.conf

@@ -59,7 +59,24 @@ top 				= farm
 [front]
 port				= 8088
 debug				= True
+xsrf_cookies		= False
 ;请求的buffersize
 max_buffer_size		= 210763776
 ;子进程
-process				= 0
+process				= 0
+url					= http://192.168.15.10:8088/device
+qrcode				= http://pan.baidu.com/share/qrcode?w=300&h=300&url=
+
+[web]
+port				= 8089
+debug				= True
+max_buffer_size		= 210763776
+process				= 0
+url					= http://192.168.15.10:8089/
+originurl			= http://s.xinnongbaohe.com/?id=
+
+;微信小程序配置
+[weixinApp]
+appid				= 1
+secret				= 1
+login				= https://api.weixin.qq.com/sns/jscode2session

+ 1 - 0
doc/apidoc.json

@@ -4,6 +4,7 @@
   "description": "农小盒接口文档",
   "title": "农小盒接口文档",
   "url" : "https://api.nongxiaohe.com",
+  "url" : "http://192.168.15.10:8088",
   "template": {
   	"withCompare": true,
   	"withGenerator": true

+ 56 - 6
front/api/device.py

@@ -66,8 +66,8 @@ class index_path(Load):
 			if not self.data['info']:
 				self.out('no')
 				return
-			self.data['status'] = self.service('common').list('device_info', state=True, search={'hardware_type--ins':(4,5), 'gateway_id':id})
-			self.data['device'] = self.service('common').list('device_info', state=True, search={'hardware_type':2, 'gateway_id':id})
+			self.data['status'] = self.service('common').list('device_info', state=True, search={'hardware_type--ins':(4,5), 'gateway_id':id}, order='inorder asc, type_id asc,udate asc,hardware_id asc')
+			self.data['device'] = self.service('common').list('device_info', state=True, search={'hardware_type':2, 'gateway_id':id}, order='inorder asc, type_id asc,udate asc,hardware_id asc')
 			if self.data['device']:
 				for key, value in enumerate(self.data['device']):
 					type = self.service('common').one('device_type', id=value['type_id'])
@@ -84,6 +84,33 @@ class index_path(Load):
 		else:
 			self.out('no')
 
+class list_path(Load):
+	"""
+	@api {get} /device/list 获取网关设备列表
+	@apiVersion 1.0.0
+	@apiName getDeviceList
+	@apiGroup Device
+
+	@apiSuccess {Object[]} setting 基本信息
+	@apiSuccess {String}   setting.name  站点名
+	@apiSuccess {Number}   setting.farm  当前的农场ID
+	
+	@apiSuccess {Object[]} list 网关信息(环境监测)
+	@apiSuccess {String}   list.name  网关名称
+	@apiSuccess {String}   list.id    网关ID
+
+	@apiErrorExample 操作成功
+	
+{"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": "229cfd36-9399-5599-b2b5-c53174c3de19", "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"stat": false, "pic": "", "hardware_id": 10086, "farm_id": 1, "cdate": 1508815174, "state": true, "camera": null, "id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "name": "\u9ed8\u8ba4\u7f51\u5173"}], "base": {}}}
+	@apiErrorExample 操作失败
+	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
+	"""
+	@auth
+	@Web.setting
+	def get(self):
+		self.data['list'] = self.service('common').list('device_gateway', search={'farm_id': Demeter.config['setting']['farm']})
+		self.out('yes', self.data)
+
 class stat_path(Load):
 	"""
 	@api {get} /device/stat 获取数据统计
@@ -149,7 +176,7 @@ class stat_path(Load):
 				self.out('no')
 				return
 			
-			self.data['device'] = self.service('common').list('device_info', state=True, search={'hardware_type':2, 'gateway_id':id})
+			self.data['device'] = self.service('common').list('device_info', state=True, search={'hardware_type':2, 'gateway_id':id}, order='inorder asc, type_id asc,udate asc,hardware_id asc')
 
 			model = Demeter.model('data', 'tsdb')
 			self.data['group'] = model.dateConfig()
@@ -237,7 +264,8 @@ class pic_path(Load):
 			search = {}
 			search['gateway_id'] = id
 			if self.data['search_date']:
-				search['cdate'] = Demeter.mktime(self.data['search_date'])
+				search['cdate-time-start'] = self.data['search_date'] + ' 00:00:00'
+				search['cdate-time-end'] = self.data['search_date'] + ' 23:59:59'
 			self.data['pic'] = self.service('common').list('device_pic', state=True, search=search, page=True)
 			if self.data['pic']:
 				for key, value in enumerate(self.data['pic']):
@@ -247,6 +275,26 @@ class pic_path(Load):
 		else:
 			self.out('no')
 
+class picup_path(Load):
+	def get(self):
+		update = {}
+		update['gateway_id'] = '542535db-6c0b-51fc-9f73-cafb3872ce76'
+		update['device_id'] = '6e78c955-e3be-5edb-b0c2-e6c5c88fd95a'
+		update['pic'] = 'http://xinnongbaohe.oss-cn-shanghai.aliyuncs.com/cp/bjbg1/1.jpg'
+		state = self.service('common').update('device_pic', False, update)
+			
+		self.out('yes', {'id':state})
+
+class msgup_path(Load):
+	def get(self):
+		update = {}
+		update['device_id'] = '6e78c955-e3be-5edb-b0c2-e6c5c88fd95a'
+		update['type_id'] = 1
+		update['content'] = '错误提示打发打发'
+		state = self.service('common').update('msg', False, update)
+			
+		self.out('yes', {'id':state})
+
 class msg_path(Load):
 	"""
 	@api {get} /device/msg 获取设备日志
@@ -290,7 +338,7 @@ class msg_path(Load):
 				self.out('no')
 				return
 
-			device = self.service('common').list('device_info', search={'gateway_id':id})
+			device = self.service('common').list('device_info', search={'gateway_id':id}, order='inorder asc, type_id asc,udate asc,hardware_id asc')
 			if not device:
 				self.out('no')
 				return
@@ -306,6 +354,8 @@ class msg_path(Load):
 			if self.data['msg']:
 				for key, value in enumerate(self.data['msg']):
 					self.data['msg'][key]['cdates'] = Demeter.date(value['cdate'])
+					type = self.service('common').one('msg_type', id=value['type_id'])
+					self.data['msg'][key]['type_name'] = type['name']
 
 			self.out('yes', self.data)
 		else:
@@ -367,7 +417,7 @@ class set_path(Load):
 	@api {post} /device/set 更新极限值设置
 	@apiVersion 1.0.0
 	@apiName updateDeviceSet
-	@apiGroup Farm
+	@apiGroup Device
 
 	@apiParam {String} id 设备id
 	@apiParam {String} update_max 最大上限

+ 6 - 0
front/api/farm.py

@@ -119,5 +119,11 @@ class msg_path(Load):
 		self.data['list'] = self.service('common').list('msg', state=True, page=True)
 		for key, value in enumerate(self.data['list']):
 			self.data['list'][key]['cdates'] = Demeter.date(value['cdate'])
+			type_info = self.service('common').one('msg_type', id=value['type_id'])
+			self.data['list'][key]['type'] = type_info['name']
+			id = value['id']
+			update = {}
+			update['status'] = True
+			self.service('common').update('msg', id, update, cdate=False)
 
 		self.out('yes', self.data)

+ 34 - 7
front/api/login.py

@@ -6,21 +6,42 @@
 	author:rabin
 """
 from __load__ import *
+import json
 
 class login_path(Load):
+	"""
+	@api {get} /login 登录绑定
+	@apiVersion 1.0.0
+	@apiName Login
+	@apiGroup Common
+
+	@apiParam {String} code 微信小程序的code
+	@apiParam {String} mobile 手机号
+	@apiParam {String} password 密码
+
+	@apiSuccess {String}   uid  用户id(加密之后的)
+
+	@apiErrorExample 操作成功
+	{"status": 1, "msg": "yes", "code": 0, "data": {"uid": "111"}]}}
+	@apiErrorExample 操作失败
+	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
+	"""
 	@Web.setting
 	def get(self):
 		mobile = self.input('mobile')
 		password = self.input('password')
 		if mobile and password:
-			user = self.service('common').one('user', mobile=mobile)
+			user = self.service('common').one('farm_user', mobile=mobile)
 			if user:
 				temp = user['password'].split('_')
 				if Demeter.md5(password, temp[1]) == user['password']:
-					self.bind(user['id'])
-					#self.set_secure_cookie('user', str(user['id']))
-					#self.redirect('/')
-					self.out('yes', {'uid':user['id']})
+					state = self.bind(user['id'])
+					if state == False:
+						self.out('手机号或密码错误,登录失败')
+					else:
+						#self.set_secure_cookie('user', str(user['id']))
+						#self.redirect('/')
+						self.out('yes', {'uid':user['id']})
 					return
 		else:
 			self.out('手机号或密码错误,登录失败')
@@ -37,5 +58,11 @@ class login_path(Load):
 		url = url + '&js_code=' + code
 		url = url + '&grant_type=authorization_code'
 		data = Demeter.curl(url)
-		
-		return data
+		data = json.loads(data.body)
+		if 'errcode' in data:
+			return False
+		update = {}
+		update['openid'] = data['openid']
+		update['session_key'] = data['session_key']
+		self.service('common').update('farm_user', uid, update)
+		return True

+ 49 - 19
front/api/origin.py

@@ -6,6 +6,43 @@
 	author:rabin
 """
 from __load__ import *
+import random
+
+class Code(object):
+	@staticmethod
+	def get(self, value):
+		cdate = Demeter.date(value['cdate'], '%Y%m%d%H%M%S')
+		#number = Demeter.compressUuid(value['id']).upper()
+		min = 1000
+		max = 9999
+		number = 'NXH' + str(value['farm_id'] + 10000) + '-' + str(value['cdate']) + str(random.randint(min, max))
+
+		info = self.service('common').one('origin_batch', number=number)
+
+		if info and info['id'] != value['id']:
+			return Code.get(self, value)
+
+		#url = Demeter.config['front']['qrcode'] + self.data['setting']['web'] + 'origin/view?qrcode=' + value['number']
+		update = {}
+		update['number'] = number
+		state = self.service('common').update('origin_batch', value['id'], update)
+		return number
+
+class Origin(object):
+	@staticmethod
+	def get(self, value):
+		value['zzdates'] = Demeter.date(value['zzdate'], '%Y-%m-%d')
+		value['csdates'] = Demeter.date(value['csdate'], '%Y-%m-%d')
+		device = self.service('common').one('device_gateway', id=value['gateway_id'])
+		value['device'] = device['name']
+		land = self.service('common').one('farm_work_land', id=value['land_id'])
+		if land:
+			value['land'] = land['name']
+		if not value['number']:
+			value['number'] = Code.get(self, value)
+		self.data['url'] = Demeter.config['web']['originurl'] + value['id'] + '&code=' + value['number']
+		value['qrcode'] = Demeter.config['front']['qrcode'] + self.data['url']
+		return value
 
 class index_path(Load):
 	"""
@@ -31,7 +68,7 @@ class index_path(Load):
 	@apiSuccess {String}   page.totalNum	总数据条数
 	
 	@apiErrorExample 操作成功
-	{"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"pic": "http://192.168.15.10:8087/upload/2017/08/30/455f9d6c26b5c989b32eda1809e58d5f.jpg", "method_id": null, "land_id": "249be20d-5759-5af0-9859-b770d9f44e2a", "farm_id": 1, "state": true, "amount": "100ml", "workdate": 1504105397, "category_id": "9365ea66-be55-56f7-a511-059fc85a9478", "cdate": 1504076614, "id": "19e05f00-ae55-5605-be12-86dcd2866df9"}], "page": {"current": 1, "ajax": false, "total": 1.0, "num": 15, "totalNum": 1}}}
+	{"status": 1, "msg": "yes", "code": 0, "data": {"url": "http://192.168.15.10:8089/origin?id=919d41a1-de9b-51f4-a1b1-46ce826fe49e&code=NXH10001-15093486295276", "setting": {"farm": 1, "user": "229cfd36-9399-5599-b2b5-c53174c3de19", "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "land": "\u5730\u57572\u53f7", "name": "test", "land_id": "6b18f8b5-c9e5-5600-8808-dad30fa4ea93", "farm_id": 1, "zzdates": "2017-10-10", "number": "NXH10001-15093486295276", "zzdate": 1507593600, "device": "\u9ed8\u8ba4\u7f51\u5173", "state": true, "csdates": "2017-10-11", "csdate": 1507680000, "qrcode": "http://pan.baidu.com/share/qrcode?w=300&h=300&url=http://192.168.15.10:8089/origin?id=919d41a1-de9b-51f4-a1b1-46ce826fe49e&code=NXH10001-15093486295276", "cdate": 1509348717, "id": "919d41a1-de9b-51f4-a1b1-46ce826fe49e"}], "page": {"current": 1, "ajax": false, "total": 1, "num": 15, "totalNum": 1}, "base": {}}}
 	@apiErrorExample 操作失败
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
@@ -41,12 +78,7 @@ class index_path(Load):
 		self.data['list'] = self.service('common').list('origin_batch', state=True, page=True)
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
-				self.data['list'][key]['zzdates'] = Demeter.date(value['zzdate'], '%Y-%m-%d')
-				self.data['list'][key]['csdates'] = Demeter.date(value['csdate'], '%Y-%m-%d')
-				device = self.service('common').one('device_gateway', id=value['gateway_id'])
-				self.data['list'][key]['device'] = device['name']
-				land = self.service('common').one('gateway_id', id=value['gateway_id'])
-				self.data['list'][key]['land'] = land['name']
+				self.data['list'][key] = Origin.get(self, value)
 		self.out('yes', self.data)
 
 	"""
@@ -76,20 +108,17 @@ class index_path(Load):
 	@Web.setting
 	def post(self):
 		id = self.input('id', None)
-		if not id:
-			self.out('no')
-			return
 		update = {}
 		update['pic'] = self.input('update_pic')
 		update['gateway_id'] = self.input('update_device_id')
-		update['land'] = self.input('update_land')
+		update['land_id'] = self.input('update_land')
 		update['zzdate'] = self.input('update_zzdate')
 		update['csdate'] = self.input('update_csdate')
 		update['name'] = self.input('update_name')
 		if not update['gateway_id']:
 			self.out(u'请选择设备')
 			return
-		if not update['land']:
+		if not update['land_id']:
 			self.out(u'请选择地块')
 			return
 		if not update['zzdate']:
@@ -101,8 +130,8 @@ class index_path(Load):
 		if not update['name']:
 			self.out(u'请输入产品名称')
 			return
-		update['zzdate'] = Demeter.mktime(update['zzdate'], '%Y-%m-%d')
-		update['csdate'] = Demeter.mktime(update['csdate'], '%Y-%m-%d')
+		#update['zzdate'] = Demeter.mktime(update['zzdate'], '%Y-%m-%d')
+		#update['csdate'] = Demeter.mktime(update['csdate'], '%Y-%m-%d')
 		state = self.service('common').update('origin_batch', id, update)
 		self.out('yes', {'id':state})
 
@@ -110,9 +139,11 @@ class info_path(Load):
 	"""
 	@api {get} /origin/info 获取溯源批次信息
 	@apiVersion 1.0.0
-	@apiName getOrigin
+	@apiName getOriginInfo
 	@apiGroup Farm
 
+	@apiParam {String} id 溯源批次id
+
 	@apiSuccess {Object[]} setting 基本信息
 	@apiSuccess {String}   setting.name  站点名
 	@apiSuccess {Number}   setting.farm  当前的农场ID
@@ -121,7 +152,7 @@ class info_path(Load):
 	@apiSuccess {String}   info.name  名称
 	@apiSuccess {String}   info.id	ID
 	@apiErrorExample 操作成功
-	{"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"pic": "http://192.168.15.10:8087/upload/2017/08/30/455f9d6c26b5c989b32eda1809e58d5f.jpg", "method_id": null, "land_id": "249be20d-5759-5af0-9859-b770d9f44e2a", "farm_id": 1, "state": true, "amount": "100ml", "workdate": 1504105397, "category_id": "9365ea66-be55-56f7-a511-059fc85a9478", "cdate": 1504076614, "id": "19e05f00-ae55-5605-be12-86dcd2866df9"}], "page": {"current": 1, "ajax": false, "total": 1.0, "num": 15, "totalNum": 1}}}
+	{"status": 1, "msg": "yes", "code": 0, "data": {"info": {"gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "land": "\u5730\u57572\u53f7", "name": "test", "land_id": "6b18f8b5-c9e5-5600-8808-dad30fa4ea93", "farm_id": 1, "zzdates": "2017-10-10", "number": "NXH10001-15093486295276", "zzdate": 1507593600, "device": "\u9ed8\u8ba4\u7f51\u5173", "state": true, "csdates": "2017-10-11", "csdate": 1507680000, "qrcode": "http://pan.baidu.com/share/qrcode?w=300&h=300&url=http://192.168.15.10:8089/origin?id=919d41a1-de9b-51f4-a1b1-46ce826fe49e&code=NXH10001-15093486295276", "cdate": 1509348717, "id": "919d41a1-de9b-51f4-a1b1-46ce826fe49e"}, "url": "http://192.168.15.10:8089/origin?id=919d41a1-de9b-51f4-a1b1-46ce826fe49e&code=NXH10001-15093486295276", "setting": {"farm": 1, "user": "229cfd36-9399-5599-b2b5-c53174c3de19", "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "base": {}}}
 	@apiErrorExample 操作失败
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
@@ -130,10 +161,9 @@ class info_path(Load):
 	def get(self):
 		id = self.input('id', None)
 		if id:
-			self.data['info'] = self.service('common').one('origin_batch', {id:id})
+			self.data['info'] = self.service('common').one('origin_batch', id=id)
 			if self.data['info']:
-				self.data['info']['zzdates'] = Demeter.date(self.data['info']['zzdate'], '%Y-%m-%d')
-				self.data['info']['csdates'] = Demeter.date(self.data['info']['csdate'], '%Y-%m-%d')
+				self.data['info'] = Origin.get(self, self.data['info'])
 				
 			self.out('yes', self.data)
 		else:

+ 142 - 17
front/api/work.py

@@ -31,22 +31,26 @@ class index_path(Load):
 	@apiSuccess {String}   page.totalNum	总数据条数
 
 	@apiErrorExample 操作成功
-	{"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"pic": "http://192.168.15.10:8087/upload/2017/08/30/455f9d6c26b5c989b32eda1809e58d5f.jpg", "method_id": null, "land_id": "249be20d-5759-5af0-9859-b770d9f44e2a", "farm_id": 1, "state": true, "amount": "100ml", "workdate": 1504105397, "category_id": "9365ea66-be55-56f7-a511-059fc85a9478", "cdate": 1504076614, "id": "19e05f00-ae55-5605-be12-86dcd2866df9"}], "page": {"current": 1, "ajax": false, "total": 1.0, "num": 15, "totalNum": 1}}}
+	
+	{"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": "229cfd36-9399-5599-b2b5-c53174c3de19", "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"category": "\u7528\u836f", "workdates": "2017-10-11", "pic": "http://www.xinnongbaohe.com:8087/upload/2017/10/10/36083979c0984547320137e5f01f7e52.jpg", "name": "2017-10-11 - \u5730\u57572\u53f7/\u7528\u836f", "land_id": "6b18f8b5-c9e5-5600-8808-dad30fa4ea93", "farm_id": 1, "state": true, "content": "22222", "amount": "30L222", "workdate": 1507680000, "category_id": "fcd8899a-a3a5-52ee-a2a8-2d5c30160044", "cdate": 1509347365, "id": "ee57691d-d4e7-533c-9111-3fc059120a7b", "land": "\u5730\u57572\u53f7"}], "page": {"current": 1, "ajax": false, "total": 1, "num": 15, "totalNum": 1}, "base": {}}}
 	@apiErrorExample 操作失败
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
 	@Web.setting
 	def get(self):
-		self.data['list'] = self.service('common').list('farm_work', state=True, page=True)
+		self.data['list'] = self.service('common').list('farm_work', state=True)
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
 				self.data['list'][key]['workdates'] = Demeter.date(value['workdate'], '%Y-%m-%d')
 				category = self.service('common').one('farm_work_category', id=value['category_id'])
 				self.data['list'][key]['category'] = category['name']
 				land = self.service('common').one('farm_work_land', id=value['land_id'])
-				self.data['list'][key]['land'] = land['name']
-				self.data['list'][key]['name'] = self.data['list'][key]['workdates'] + ' - ' + land['name'] + '/' + category['name']
+				if land:
+					self.data['list'][key]['land'] = land['name']
+					self.data['list'][key]['name'] = self.data['list'][key]['workdates'] + ' - ' + land['name'] + '/' + category['name']
+				else:
+					self.data['list'][key]['name'] = self.data['list'][key]['workdates'] + '/' + category['name']
 		self.out('yes', self.data)
 
 	"""
@@ -76,20 +80,17 @@ class index_path(Load):
 	@Web.setting
 	def post(self):
 		id = self.input('id', None)
-		if not id:
-			self.out('no')
-			return
 		update = {}
 		update['pic'] = self.input('update_pic')
-		update['category'] = self.input('update_category')
-		update['land'] = self.input('update_land')
+		update['category_id'] = self.input('update_category')
+		update['land_id'] = self.input('update_land')
 		update['workdate'] = self.input('update_workdate')
 		update['content'] = self.input('update_content')
 		update['amount'] = self.input('update_amount')
-		if not update['category']:
+		if not update['category_id']:
 			self.out(u'请选择农事方式')
 			return
-		if not update['land']:
+		if not update['land_id']:
 			self.out(u'请选择地块')
 			return
 		if not update['workdate']:
@@ -101,7 +102,7 @@ class index_path(Load):
 		if not update['amount']:
 			self.out(u'请输入劳作数量')
 			return
-		update['workdate'] = Demeter.mktime(update['workdate'], '%Y-%m-%d')
+		#update['workdate'] = Demeter.mktime(update['workdate'], '%Y-%m-%d')
 		state = self.service('common').update('farm_work', id, update)
 		self.out('yes', {'id':state})
 
@@ -109,9 +110,11 @@ class info_path(Load):
 	"""
 	@api {get} /work/info 获取农事信息
 	@apiVersion 1.0.0
-	@apiName getWork
+	@apiName getWorkInfo
 	@apiGroup Farm
 
+	@apiParam {String} id 农事ID
+
 	@apiSuccess {Object[]} setting 基本信息
 	@apiSuccess {String}   setting.name  站点名
 	@apiSuccess {Number}   setting.farm  当前的农场ID
@@ -129,7 +132,7 @@ class info_path(Load):
 	def get(self):
 		id = self.input('id', None)
 		if id:
-			self.data['info'] = self.service('common').one('farm_work', {id:id})
+			self.data['info'] = self.service('common').one('farm_work', id=id)
 			if self.data['info']:
 				self.data['info']['workdates'] = Demeter.date(self.data['info']['workdate'], '%Y-%m-%d')
 				
@@ -152,7 +155,7 @@ class land_path(Load):
 	@apiSuccess {String}   list.name  名称
 	@apiSuccess {String}   list.id	ID
 	@apiErrorExample 操作成功
-	{"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"state": true, "farm_id": 1, "cdate": 1504074548, "id": "249be20d-5759-5af0-9859-b770d9f44e2a", "name": "test"}]}}
+	{"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": "229cfd36-9399-5599-b2b5-c53174c3de19", "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"state": true, "farm_id": 1, "cdate": 1509344166, "id": "6b18f8b5-c9e5-5600-8808-dad30fa4ea93", "name": "\u5730\u57572\u53f7"}, {"state": true, "farm_id": 1, "cdate": 1509344164, "id": "17b881d4-ea79-5968-8328-4d7587cf3e39", "name": "\u5730\u57571\u53f7"}], "base": {}}}
 	@apiErrorExample 操作失败
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
@@ -192,6 +195,98 @@ class land_path(Load):
 		state = self.service('common').update('farm_work_land', id, update)
 		self.out('yes', {'id':state})
 
+	"""
+	@api {delete} /work/land 删除地块
+	@apiVersion 1.0.0
+	@apiName updateWorkLand
+	@apiGroup Farm
+
+	@apiParam {String} id 地块ID,为空则插入新记录
+
+	@apiSuccess {Bool} status 状态
+	@apiSuccess {String}   msg  描述
+	@apiSuccess {Number}   code  状态码
+
+	@apiErrorExample 操作成功
+	{"status": 1, "msg": "操作成功", "code": 0, "data": {}}
+	@apiErrorExample 操作失败
+	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
+	"""
+	@auth
+	@Web.setting
+	def delete(self):
+		id = self.input('id')
+		if id:
+			model = Demeter.model('farm_work_land')
+			model.id = id
+			model.delete()
+		self.out('yes', {'id':id})
+
+class land_pic_path(Load):
+	"""
+	@api {get} /work/land_pic 获取农事地块图片列表
+	@apiVersion 1.0.0
+	@apiName getWorkLandPicList
+	@apiGroup Farm
+
+	@apiSuccess {Object[]} setting 基本信息
+	@apiSuccess {String}   setting.name  站点名
+	@apiSuccess {Number}   setting.farm  当前的农场ID
+
+	@apiSuccess {Object[]} list 地块列表信息
+	@apiSuccess {String}   list.name  名称
+	@apiSuccess {String}   list.id	ID
+	@apiSuccess {Object[]}   list.pic	图片
+
+	@apiErrorExample 操作成功
+	{"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": "229cfd36-9399-5599-b2b5-c53174c3de19", "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"farm_id": 1, "name": "222", "pic": [{"pic": "http://192.168.15.10:8088/upload/2017/11/01/a7164193b56a074d72e4f94e4a4d145c.jpg", "land_id": "d508f554-db86-52dc-ba20-fbb476c60abc", "farm_id": 1, "state": true, "cdate": 1509519631, "id": "0d11d5ee-990e-52d5-ae55-09a212834f0d"}], "cdate": 1509519537, "state": true, "id": "d508f554-db86-52dc-ba20-fbb476c60abc"}, {"farm_id": 1, "name": "111", "pic": [], "cdate": 1509519533, "state": true, "id": "03679a19-f619-55d3-959c-bbc0a22dc072"}], "base": {}}}
+	@apiErrorExample 操作失败
+	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
+	"""
+	@auth
+	@Web.setting
+	def get(self):
+		self.data['list'] = self.service('common').list('farm_work_land', state=True)
+		#self.data['list'] = self.service('common').list('farm_work_land_pic', state=True)
+		if self.data['list']:
+			for key, value in enumerate(self.data['list']):
+				self.data['list'][key]['pic'] = self.service('common').list('farm_work_land_pic', search={'land_id':value['id']}, state=True)
+		self.out('yes', self.data)
+
+	"""
+	@api {post} /work/land_pic 更新地块图片
+	@apiVersion 1.0.0
+	@apiName updateWorkLandPic
+	@apiGroup Farm
+
+	@apiParam {String} update_land_id 地块ID,为空则插入新记录
+	@apiParam {String} update_pic 地块图片地址
+
+	@apiSuccess {Bool} status 状态
+	@apiSuccess {String}   msg  描述
+	@apiSuccess {Number}   code  状态码
+
+	@apiErrorExample 操作成功
+	{"status": 1, "msg": "操作成功", "code": 0, "data": {}}
+	@apiErrorExample 操作失败
+	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
+	"""
+	@auth
+	@Web.setting
+	def post(self):
+		id = self.input('id', None)
+		update = {}
+		update['land_id'] = self.input('update_land_id')
+		update['pic'] = self.input('update_pic')
+		if not update['land_id']:
+			self.out(u'请选择地块')
+			return
+		if not update['pic']:
+			self.out(u'请上传地块图片')
+			return
+		state = self.service('common').update('farm_work_land_pic', id, update)
+		self.out('yes', {'id':state})
+
 class category_path(Load):
 	"""
 	@api {get} /work/category 获取农事分类列表
@@ -207,7 +302,7 @@ class category_path(Load):
 	@apiSuccess {String}   list.name  名称
 	@apiSuccess {String}   list.id	ID
 	@apiErrorExample 操作成功
-	{"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"state": true, "farm_id": 1, "cdate": 1504074837, "id": "9365ea66-be55-56f7-a511-059fc85a9478", "name": "\u65bd\u80a5"}]}}
+	{"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": "229cfd36-9399-5599-b2b5-c53174c3de19", "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"state": true, "farm_id": 1, "cdate": 1509344125, "id": "fcd8899a-a3a5-52ee-a2a8-2d5c30160044", "name": "\u7528\u836f"}, {"state": true, "farm_id": 1, "cdate": 1509344107, "id": "6f955928-9724-5cb7-acd0-a81d482d9883", "name": "\u65bd\u80a5"}], "base": {}}}
 	@apiErrorExample 操作失败
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
@@ -215,4 +310,34 @@ class category_path(Load):
 	@Web.setting
 	def get(self):
 		self.data['list'] = self.service('common').list('farm_work_category', state=True)
-		self.out('yes', self.data)
+		self.out('yes', self.data)
+
+	"""
+	@api {post} /work/category 更新农事分类
+	@apiVersion 1.0.0
+	@apiName updateWorkCategory
+	@apiGroup Farm
+
+	@apiParam {String} id 分类ID,为空则插入新记录
+	@apiParam {String} update_name 分类名称
+
+	@apiSuccess {Bool} status 状态
+	@apiSuccess {String}   msg  描述
+	@apiSuccess {Number}   code  状态码
+
+	@apiErrorExample 操作成功
+	{"status": 1, "msg": "操作成功", "code": 0, "data": {}}
+	@apiErrorExample 操作失败
+	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
+	"""
+	@auth
+	@Web.setting
+	def post(self):
+		id = self.input('id', None)
+		update = {}
+		update['name'] = self.input('update_name')
+		if not update['name']:
+			self.out(u'请输入分类名称')
+			return
+		state = self.service('common').update('farm_work_category', id, update)
+		self.out('yes', {'id':state})

+ 2 - 2
install.py

@@ -37,7 +37,7 @@ def web():
 		model.insert()
 
 	model = Demeter.model('web_article_category')
-	data = ('站点介绍','日志','首页焦点图', '产品功能', '客户案例')
+	data = ('站点介绍', '日志', '产品功能', '客户案例')
 	for value in data:
 		model.name = value
 		info = model.select(type='fetchone')
@@ -59,7 +59,7 @@ def web():
 	data = (
 		{'name':'首页','link':'/main'}
 		,{'name':'农小盒日志','link':'/article'}
-		,{'name':'联系我们','link':'/article/view?id=1'}
+		,{'name':'联系我们','link':'/us'}
 		)
 	for value in data:
 		model.link = value['link']

+ 2 - 0
model/farm_user.py

@@ -15,5 +15,7 @@ class Farm_user(Model):
 	username = Fields(type='varchar(50)', comment='园区管理员姓名')
 	mobile = Fields(type='bigint', comment='园区管理员手机号', unique=True)
 	password = Fields(type='varchar(38)', comment='安全密码', md5=True)
+	openid = Fields(type='varchar(50)', comment='wx openid')
+	session_key = Fields(type='varchar(50)', comment='session_key')
 	state = Fields(type='boolean', default='True', comment='数据存在状态')
 	cdate = Fields(type='int', default='time', comment='创建时间')

+ 1 - 0
model/farm_work.py

@@ -13,6 +13,7 @@ class Farm_work(Model):
 	id = Fields(type='uuid', primaryKey=True, comment='农事ID', uuid='farm_id')
 	farm_id = Fields(type='int', default='setting.farm', comment='园区ID', match='not')
 	amount = Fields(type='varchar(150)', comment='劳作用量')
+	content = Fields(type='varchar(250)', comment='劳作内容')
 	category_id = Fields(type='uuid', comment='劳作分类id')
 	land_id = Fields(type='uuid', comment='地块id')
 	pic = Fields(type='varchar(255)', comment='图像记录')

+ 22 - 21
model/origin_batch.py

@@ -1,22 +1,23 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
-    demeter database
-    name:origin_batch.py
-    author:rabin
-"""
-from __load__ import *
-
-class Origin_batch(Model):
-	__table__ = 'origin_batch'
-	__comment__ = '溯源批次表'
-	id = Fields(type='uuid', primaryKey=True, comment='批次ID', uuid='farm_id')
-	farm_id = Fields(type='int', default='setting.farm', comment='园区ID', match='not')
-	name = Fields(type='varchar(150)', comment='产品名')
-	zzdate = Fields(type='int', comment='种植时间')
-	csdate = Fields(type='int', comment='采收时间')
-	land_id = Fields(type='uuid', comment='地块id')
-	gateway_id = Fields(type='uuid', comment='网关id')
-	number = Fields(type='varchar(32)', comment='批号')
-	state = Fields(type='boolean', default='True', comment='数据存在状态')
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    demeter database
+    name:origin_batch.py
+    author:rabin
+"""
+from __load__ import *
+
+class Origin_batch(Model):
+	__table__ = 'origin_batch'
+	__comment__ = '溯源批次表'
+	id = Fields(type='uuid', primaryKey=True, comment='批次ID', uuid='farm_id')
+	farm_id = Fields(type='int', default='setting.farm', comment='园区ID', match='not')
+	name = Fields(type='varchar(150)', comment='产品名')
+	zzdate = Fields(type='int', comment='种植时间')
+	csdate = Fields(type='int', comment='采收时间')
+	land_id = Fields(type='uuid', comment='地块id')
+	gateway_id = Fields(type='uuid', comment='网关id')
+	number = Fields(type='varchar(32)', comment='批号')
+	pic = Fields(type='varchar(255)', comment='图像记录')
+	state = Fields(type='boolean', default='True', comment='数据存在状态')
 	cdate = Fields(type='int', default='time', comment='创建时间')

+ 0 - 18
model/web_help.py

@@ -1,18 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
-    demeter database
-    name:help.py
-    author:rabin
-"""
-from __load__ import *
-
-class Web_help(Model):
-	__table__ = 'web_help'
-	__comment__ = '帮助内容表'
-	id = Fields(type='int', primaryKey=True, autoIncrement=True, comment='ID')
-	category_id = Fields(type='int', comment='分类ID', match='not')
-	name = Fields(type='varchar(255)', comment='内容名')
-	content = Fields(type='text', comment='文章内容')
-	state = Fields(type='boolean', default='True', comment='数据存在状态')
-	cdate = Fields(type='int', default='time', comment='创建时间')

+ 0 - 16
model/web_help_category.py

@@ -1,16 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
-    demeter database
-    name:web_help_category.py
-    author:rabin
-"""
-from __load__ import *
-
-class Web_help_category(Model):
-	__table__ = 'web_help_category'
-	__comment__ = '帮助分类表'
-	id = Fields(type='int', primaryKey=True, autoIncrement=True, comment='ID')
-	name = Fields(type='varchar(50)', comment='分类名')
-	state = Fields(type='boolean', default='True', comment='数据存在状态')
-	cdate = Fields(type='int', default='time', comment='创建时间')

+ 4 - 3
model/web_set.py

@@ -15,10 +15,11 @@ class Web_set(Model):
 	subname = Fields(type='varchar(255)', comment='子标题')
 	keywords = Fields(type='varchar(255)', comment='关键词')
 	description = Fields(type='varchar(255)', comment='描述')
-	passtel = Fields(type='varchar(255)', comment='忘记密码电话')
 	tel = Fields(type='varchar(255)', comment='联系电话')
 	icp = Fields(type='varchar(255)', comment='icp备案')
-	buy = Fields(type='text', comment='首页购买')
-	mobile = Fields(type='text', comment='首页手机')
+	video = Fields(type='varchar(255)', comment='视频播放地址')
+	wx_pic = Fields(type='varchar(255)', comment='微信管理图片')
+	wx_text = Fields(type='varchar(255)', comment='微信管理图片')
+	wx_link = Fields(type='varchar(255)', comment='微信管理图片')
 	state = Fields(type='boolean', default='True', comment='数据存在状态')
 	cdate = Fields(type='int', default='time', comment='创建时间')