rabin 7 лет назад
Родитель
Сommit
a80457b40a
3 измененных файлов с 32 добавлено и 7 удалено
  1. 25 4
      admin/page/farm.py
  2. 6 2
      front/api/login.py
  3. 1 1
      model/farm_user_wechat.py

+ 25 - 4
admin/page/farm.py

@@ -136,10 +136,10 @@ class user_wechat_path(Load):
 			,width = '600'
 			,height = '400'
 			,add = False
-			,edit = False
+			#,edit = False
 			,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','uid-input-'), (u'日期范围',u'开始时间',u'截止时间','选择农场',u'用户id'))
-			,thead = (u'所属农场', u'用户id', u'微信openid', u'更新时间')
-			,tbody = ('farm','uid','openid', 'cdate')
+			,thead = (u'所属农场', u'微信昵称', u'微信openid', u'更新时间')
+			,tbody = ('farm','nickname','openid', 'cdate')
 			,state = True
 		)
 
@@ -150,4 +150,25 @@ class user_wechat_path(Load):
 			for key, value in enumerate(self.data['list']):
 				farm = self.service('common').one('farm', id=value['farm_id'])
 				self.data['list'][key]['farm'] = farm['name']
-		self.commonView('list')
+		self.commonView('list')
+
+class user_wechat_update_path(Load):
+	@Web.auth
+	@Web.setting
+	def get(self):
+		self.common(
+			path = '/farm/user_wechat'
+			,label = (u'微信昵称',)
+			,update = ('nickname-input-required',)
+			,update_farm_id = Demeter.config['setting']['farmList']
+		)
+		self.commonOne('farm_user_wechat')
+		self.commonView('update')
+	@Web.auth
+	@Web.setting
+	def post(self):
+		self.commonUpdate('farm_user_wechat')
+	@Web.auth
+	@Web.setting
+	def delete(self):
+		self.commonDelete('farm_user_wechat')

+ 6 - 2
front/api/login.py

@@ -29,12 +29,15 @@ class login_path(Load):
 	def get(self):
 		mobile = self.input('mobile')
 		password = self.input('password')
+		nickname = self.input('nickname')
 		if mobile and password:
 			user = self.service('common').one('farm_user', mobile=mobile)
 			if user:
 				temp = user['password'].split('_')
 				if Demeter.md5(password, temp[1]) == user['password']:
-					state = self.bind(user['id'])
+					if not nickname:
+						nickname = user['username']
+					state = self.bind(user['id'], nickname)
 					if state == False:
 						self.out('手机号或密码错误,登录失败')
 					else:
@@ -46,7 +49,7 @@ class login_path(Load):
 			self.out('手机号或密码错误,登录失败')
 			return
 
-	def bind(self, uid):
+	def bind(self, uid, nickname):
 		code = self.input('code')
 		if not code:
 			self.out('no')
@@ -67,6 +70,7 @@ class login_path(Load):
 		wechat = self.service('common').one('farm_user_wechat', uid=uid, openid=update['openid'])
 		if not wechat:
 			update = {}
+			update['nickname'] = nickname
 			update['openid'] = data['openid']
 			update['session_key'] = data['session_key']
 			update['uid'] = uid

+ 1 - 1
model/farm_user_wechat.py

@@ -12,7 +12,7 @@ class Farm_user_wechat(Model):
 	__comment__ = '园区用户微信绑定表'
 	id = Fields(type='uuid', primaryKey=True, comment='园区用户微信绑定表ID', uuid='farm_id')
 	farm_id = Fields(type='int', default='setting.farm', comment='园区ID', match='not')
-	username = Fields(type='varchar(50)', comment='园区管理员姓名')
+	nickname = Fields(type='varchar(150)', comment='微信昵称')
 	uid = Fields(type='uuid', comment='用户id')
 	openid = Fields(type='varchar(50)', comment='wx openid')
 	session_key = Fields(type='varchar(50)', comment='session_key')