def get(self): item_list = [] for i in xrange(1, 10000): item = Items() item.itemId = i item.itemCount = random.randrange(1000, 50000) item.activityPrice = random.randrange(30, 500) item.originalPrice = item.activityPrice + 200 dis = (item.activityPrice / item.originalPrice) * 10 item.discount = '%1.1f' % dis item.soldCount = random.randrange(10, 10000) item.shortName = random.choice(pinpai) + random.choice(['国际知名品牌,值得信赖', '创造更加监控生活,极致卓越表现', ' 将体育精神融汇于每一步行走、每一次挥手']) item.picUrl = random.choice(img) item_list.append(item) page_no = int(self.get_argument('page_no', 0)) page_size = int(self.get_argument("page_size", 10)) msg = "" start = page_no * page_size end = start + page_size if end > len(item_list): data = "" msg = "item is null" else: data = item_list[start:end] if data: res = ApiCommonResult(name="JuItemAPI", data=data, success=True, msg=msg) else: res = ApiCommonResult(data=data, success=False, name="JuItemAPI", msg=msg) return self.write(res.to_json())
def get(self): peixunImg = "http://gju4.alicdn.com/bao/uploaded/i4/T1bt_dFgRaXXb1upjX.jpg_640x480.jpg" peixunImg1 = "http://gju2.alicdn.com/bao/uploaded/i1/T190q1FhJeXXb1upjX.jpg_640x480.jpg" peixunImgArry = [peixunImg, peixunImg1] #res = ApiCommonResult(data=peixunImgArry) res = ApiCommonResult(data=category) self.set_header("aaaa", "peixun") self.write(res.to_json())
def get(self): peixunImg = "http://gju4.alicdn.com/bao/uploaded/i4/T1bt_dFgRaXXb1upjX.jpg_640x480.jpg" peixunImg1 = "http://gju2.alicdn.com/bao/uploaded/i1/T190q1FhJeXXb1upjX.jpg_640x480.jpg" peixunImgArry = [peixunImg, peixunImg1] #res = ApiCommonResult(data=peixunImgArry) res = ApiCommonResult(data=category) self.set_header("aaaa","peixun") self.write(res.to_json())
def get(self): str_userid=self.get_argument("user_id") str_usernick=self.get_argument("user_nick",default="YOYO") str_phonenum=self.get_argument("phone_num",default=1234) sqlobjc=myqslOperation() sqlobjc.update_user_info(self.db,str_userid,str_usernick,str_phonenum) resultDict={"result":"ok"} json_res=ApiCommonResult(resultDict) self.write(json_res.to_json())
def get(self): str_userid = self.get_argument("user_id") str_usernick = self.get_argument("user_nick", default="YOYO") str_phonenum = self.get_argument("phone_num", default=1234) sqlobjc = myqslOperation() sqlobjc.update_user_info(self.db, str_userid, str_usernick, str_phonenum) resultDict = {"result": "ok"} json_res = ApiCommonResult(resultDict) self.write(json_res.to_json())
def get(self): #同意添加好友 str_from_id = self.get_argument("fromId") str_to_id = self.get_argument("toId") sqlobjc = myqslOperation() is_update = sqlobjc.update_friend_releation(self.db, str_from_id, str_to_id, 1) if is_update: self.write(ApiCommonResult(g_resdict).to_json()) else: resultDict = {"result": "false"} self.write(ApiCommonResult(resultDict).to_json())
def get(self): #判断是否有还有添加我的消息 str_userid = self.get_argument("user_id") sqlObjc = myqslOperation() list = sqlObjc.get_is_have_addfriend_msg(self.db,str_userid) res_dict = {"result":"ok"} if list: json_res = ApiCommonResult(res_dict) self.write(json_res.to_json()) else: res_dict["result"]="fail" json_res = ApiCommonResult(res_dict) self.write(json_res.to_json())
def get(self): str_userid = self.get_argument("user_id") sqlObjc = myqslOperation() list1 = sqlObjc.get_is_have_addfriend_msg(self.db,str_userid) res_dict = {"result":None} resultList=[] if list1: for msgDict in list1: from_list=sqlObjc.querySQL(self.db,msgDict["from_id"]) resultDict = {"fromNick":from_list[0]["user_nick"],"fromId":msgDict["from_id"],"toNick":"","toId":msgDict["to_id"]} resultList.append(resultDict) json_res = ApiCommonResult(resultList) self.write(json_res.to_json()) else: json_res = ApiCommonResult(res_dict) self.write(json_res.to_json())
def get(self): strFromUserid = self.get_argument("fromUserid") strToUserid = self.get_argument("toUserid") sqlObjc = myqslOperation() isAddRecord = sqlObjc.get_is_addrecord_relation(self.db,strFromUserid,strToUserid) resDict = {"status":0} if not isAddRecord: to_from_list = sqlObjc.get_friend_relation(self.db,strToUserid) if to_from_list: for a in to_from_list: if a.to_id == strFromUserid:#同时修改to-from的status值 sqlObjc.update_friend_releation(self.db,strToUserid,strFromUserid,1) resDict = {"status":1} break else: resDict={"status":2} if resDict["status"]!=2: sqlObjc.insertFriendRelation(strFromUserid,strToUserid,resDict["status"],self.db) jsonRes = ApiCommonResult(resDict) self.write(jsonRes.to_json())
def get(self): strUserid = self.get_argument("userid") mysql = myqslOperation() list = mysql.querySQL(self.db,strUserid) if list: jsonRes = ApiCommonResult(list) self.write(jsonRes.to_json()) else: jsonRes = ApiCommonResult(list) jsonRes.success=False self.write(jsonRes.to_json())
def get(self): item_list = [] for i in xrange(1, 10000): item = Items() item.itemId = i item.itemCount = random.randrange(1000, 50000) item.activityPrice = random.randrange(30, 500) item.originalPrice = item.activityPrice + 200 dis = (item.activityPrice / item.originalPrice) * 10 item.discount = '%1.1f' % dis item.soldCount = random.randrange(10, 10000) item.shortName = random.choice(pinpai) + random.choice( ['国际知名品牌,值得信赖', '创造更加监控生活,极致卓越表现', ' 将体育精神融汇于每一步行走、每一次挥手']) item.picUrl = random.choice(img) item_list.append(item) page_no = int(self.get_argument('page_no', 0)) page_size = int(self.get_argument("page_size", 10)) msg = "" start = page_no * page_size end = start + page_size if end > len(item_list): data = "" msg = "item is null" else: data = item_list[start:end] if data: res = ApiCommonResult(name="JuItemAPI", data=data, success=True, msg=msg) else: res = ApiCommonResult(data=data, success=False, name="JuItemAPI", msg=msg) return self.write(res.to_json())
def get(self): strFromUserid = self.get_argument("fromUserid") strToUserid = self.get_argument("toUserid") sqlObjc = myqslOperation() isAddRecord = sqlObjc.get_is_addrecord_relation( self.db, strFromUserid, strToUserid) resDict = {"status": 0} if not isAddRecord: to_from_list = sqlObjc.get_friend_relation(self.db, strToUserid) if to_from_list: for a in to_from_list: if a.to_id == strFromUserid: #同时修改to-from的status值 sqlObjc.update_friend_releation( self.db, strToUserid, strFromUserid, 1) resDict = {"status": 1} break else: resDict = {"status": 2} if resDict["status"] != 2: sqlObjc.insertFriendRelation(strFromUserid, strToUserid, resDict["status"], self.db) jsonRes = ApiCommonResult(resDict) self.write(jsonRes.to_json())
def get(self): #获取好友 resultlist = None if self.get_argument("userId"): str_userid = self.get_argument("userId") if self.get_argument("friTime"): str_fritime = self.get_argument("friTime") if str_userid: sqlobjc = myqslOperation() friendlist = sqlobjc.get_user_friend(self.db, str_userid, str_fritime) packlist = self.packet_friend(friendlist, str_userid, sqlobjc) if packlist: resultlist = packlist[0] currentTime = packlist[1] self.write(ApiCommonResult(resultlist, cTime=currentTime).to_json())
def get(self): #判断是否有还有添加我的消息 str_userid = self.get_argument("user_id") sqlObjc = myqslOperation() list = sqlObjc.get_is_have_addfriend_msg(self.db, str_userid) res_dict = {"result": "ok"} if list: json_res = ApiCommonResult(res_dict) self.write(json_res.to_json()) else: res_dict["result"] = "fail" json_res = ApiCommonResult(res_dict) self.write(json_res.to_json())
def get(self): str_userid = self.get_argument("user_id") sqlObjc = myqslOperation() list1 = sqlObjc.get_is_have_addfriend_msg(self.db, str_userid) res_dict = {"result": None} resultList = [] if list1: for msgDict in list1: from_list = sqlObjc.querySQL(self.db, msgDict["from_id"]) resultDict = { "fromNick": from_list[0]["user_nick"], "fromId": msgDict["from_id"], "toNick": "", "toId": msgDict["to_id"] } resultList.append(resultDict) json_res = ApiCommonResult(resultList) self.write(json_res.to_json()) else: json_res = ApiCommonResult(res_dict) self.write(json_res.to_json())