def get_size(self): if not is_admin(): return TOKEN_ERROR list = get_model_return_list(self.sgoods.get_size_list()) response = import_status("get_size_list_success", "OK") response['data'] = list return response
def delete_category(self): #删除商品分类 #self.json_param_miss("post") if not is_admin(): return AUTHORITY_ERROR try: data = request.json PAid = data.get('PAid') except: return PARAMS_ERROR try: get_PAstatus = get_model_return_dict(self.sgoods.get_product_category(PAid)) if not get_PAstatus: return PRODUCE_CATEGORY_NOT_EXIST # elif get_Parentid == 0: # self.sgoods.add_product_category(PAid, PAname, PAtype) if get_PAstatus['PAtype'] == 1: categorylist = get_model_return_list(self.sgoods.get_first_product_category_status(PAid)) if categorylist: return HAS_SECOND_CATEGORY if get_PAstatus['PAtype'] == 2: product_list = get_model_return_list(self.sgoods.get_product_by_paid(paid=PAid)) if product_list: return PRODUCE_CATEGORY_HAS_PRODUCT delete_category = {} delete_category['PAstatus'] = False self.sgoods.delete_category(PAid, delete_category) except Exception as e: print e.message return PARAMS_MISS response = import_status("delete_product_category_success", "OK") return response
def get_comMessage(self): if is_tourist(): return TOKEN_ERROR try: args = request.args.to_dict() page = int(args.get('page', 1)) # 页码 count = int(args.get('count', 10)) # 取出条数 except Exception as e: return PARAMS_ERROR if is_admin(): comMessage_list = get_model_return_list( self.smessage.get_comMessage_list(page, count)) # 分页查询出的公司消息列表 from common.timeformat import get_web_time_str for message in comMessage_list: message['CMdate'] = get_web_time_str(message['CMdate']) comMessage_num = self.smessage.get_commessage_num() # 公司消息总条数 data = import_status('get_commessage_list_success', 'OK') data['mount'] = int(comMessage_num) data['data'] = comMessage_list return data else: comMessage_num = self.smessage.get_commessage_num() # 公司消息总条数 print comMessage_num comMessage_list = get_model_return_list( self.smessage.get_comMessage_list(page, count)) # 分页查询出的公司消息列表 print len(comMessage_list) a = request.user.id already_list = get_model_return_list( self.smessage.get_alreadyMessage_by_usid( request.user.id)) # 已经阅读的消息的id集合 already_id_list = [] for already in already_list: already_id_list.append(already['ARmessageid']) notread_count = int(comMessage_num) - len( already_list) # 该用户未读的消息条数 return_message_list = [] from common.timeformat import get_web_time_str for message in comMessage_list: message_dic = {} if message['CMid'] not in already_id_list: # 如果没有读,加个标记isread message_dic['isread'] = 0 message_dic['CMid'] = message['CMid'] message_dic['CMdate'] = get_web_time_str(message['CMdate']) message_dic['CMtype'] = message['CMtype'] message_dic['CMtitle'] = message['CMtitle'] message_dic['CMfile'] = message['CMfile'] return_message_list.append(message_dic) else: message_dic['isread'] = 1 message_dic['CMid'] = message['CMid'] message_dic['CMdate'] = get_web_time_str(message['CMdate']) message_dic['CMtype'] = message['CMtype'] message_dic['CMtitle'] = message['CMtitle'] message_dic['CMfile'] = message['CMfile'] return_message_list.append(message_dic) data = import_status('get_commessage_list_success', 'OK') data['notread'] = notread_count data['data'] = return_message_list data['mount'] = int(comMessage_num) return data
def remove_file(self): if is_ordirnaryuser() or is_admin(): try: data = request.json url = str(data.get('url')) except: return PARAMS_ERROR real_url = "/opt/beili/file/" + url if request.user.id not in real_url: return AUTHORITY_ERROR try: os.remove(real_url) response = import_status("remove_file_success", "OK") return response except: return AUTHORITY_ERROR elif is_temp(): try: data = request.json url = str(data.get('url')) except: return PARAMS_ERROR real_url = "/opt/beili/file/" + url if request.temp not in real_url: return AUTHORITY_ERROR try: os.remove(real_url) response = import_status("remove_file_success", "OK") return response except: return AUTHORITY_ERROR else: return TOKEN_ERROR
def update_category(self): #更新商品分类 #self.json_param_miss("post") if not is_admin(): return AUTHORITY_ERROR try: data = request.json PAid = data.get('PAid') PAname = data.get('PAname') PAtype = data.get('PAtype') Parentid = data.get('Parentid') except: return PARAMS_ERROR try: get_PAstatus = get_model_return_dict(self.sgoods.get_product_category(PAid)) if not get_PAstatus: return PRODUCE_CATEGORY_NOT_EXIST if PAtype != get_PAstatus['PAtype']: return CAN_NOT_CHANGE_LEVEL update_category = {} update_category['PAname'] = PAname update_category['PAtype'] = PAtype update_category['Parentid'] = Parentid print Parentid self.sgoods.update_product_category(PAid, update_category) except Exception as e : print Exception return PARAMS_MISS response = import_status("update_product_category_success", "OK") return response
def add_product_category(self): #添加商品分类 #self.json_param_miss("post") if not is_admin(): return AUTHORITY_ERROR try: data = request.json print data, type(data) PAid = data.get('PAid') PAname = data.get('PAname') PAtype = data.get('PAtype') Parentid = data.get('Parentid') except Exception as e: print e.message return PARAMS_ERROR try: get_PAstatus = get_model_return_dict(self.sgoods.get_product_category(PAid)) if get_PAstatus: update_category = {} update_category['PAname'] = PAname update_category['Parentid'] = Parentid if Parentid else '0' print Parentid self.sgoods.update_product_category(PAid, update_category) else: PAid = str(uuid.uuid1()) Parentid = Parentid if Parentid else '0' self.sgoods.add_product_category(PAid, PAname, PAtype, Parentid) except Exception as e: print e.message return PARAMS_MISS response = import_status("add_product_category_success", "OK") #response["data"] = product_category return response
def get_commessage_details(self): if is_tourist(): return TOKEN_ERROR try: args = request.args.to_dict() messageid = args.get('messageid') except Exception as e: return PARAMS_ERROR message = get_model_return_dict( self.smessage.get_commessage_details(messageid)) from common.timeformat import get_web_time_str message['CMdate'] = get_web_time_str(message['CMdate']) data = import_status('get_commessage_details_success', 'OK') data['data'] = message if is_admin(): return data else: try: note = self.smessage.get_isread(messageid, request.user.id) if note: return data else: self.smessage.insert_alreadyread(str(uuid.uuid4()), messageid, request.user.id) return data except Exception as e: print 'repeat'
def publish_commessage(self): if not is_admin(): return AUTHORITY_ERROR files = request.files.get("file") try: json_data = request.json type = json_data.get('type') title = json_data.get('title') except Exception as e: return PARAMS_ERROR if not type or not title or not file: return PARAMS_MISS if platform.system() == "Windows": rootdir = "D:/task" else: rootdir = "/opt/beili/file/message/" if not os.path.isdir(rootdir): os.mkdir(rootdir) # lastpoint = str(files.filename).rindex(".") # filessuffix = str(files.filename)[lastpoint + 1:] fileallname = get_db_time_str() + str(files.filename) filepath = os.path.join(rootdir, fileallname) files.save(filepath) url = QRCODEHOSTNAME + "/file/message/" + fileallname # 获取当前时间 import datetime from common.timeformat import format_for_db time_time = datetime.datetime.now() time_str = datetime.datetime.strftime(time_time, format_for_db) id = str(uuid.uuid4()) self.smessage.publish_commessage(id, time_str, type, title, url) response = import_status("publish_message_success", "OK") return response
def get_register_record(self): if not is_admin(): return TOKEN_ERROR try: data = request.json status = int(data.get('status')) page_size = data.get('page_size') page_num = data.get('page_num') except: return PARAMS_ERROR list = get_model_return_list(self.suser.get_register_record(status)) if not list: response = import_status("get_registerinfo_success", "OK") response['data'] = [] return response from common.timeformat import get_web_time_str for record in list: record['IRIcreatetime'] = get_web_time_str(record['IRIcreatetime']) record['IRIpaytime'] = get_web_time_str(record['IRIpaytime']) record['IRIproof'] = record['IRIproof'].split(',') if record['IRIarea']: area = get_model_return_dict( self.smycenter.get_area_by_areaid(record['IRIarea'])) city = get_model_return_dict( self.smycenter.get_city_by_cityid(area['cityid'])) province = get_model_return_dict( self.smycenter.get_province_by_provinceid( city['provinceid'])) record['address'] = province['provincename'] + city[ 'cityname'] + area['areaname'] else: city = get_model_return_dict( self.smycenter.get_city_by_cityid(record['IRIcity'])) province = get_model_return_dict( self.smycenter.get_province_by_provinceid( city['provinceid'])) record['address'] = province['provincename'] + city['cityname'] mount = len(list) page = mount / page_size if page == 0 or page == 1 and mount % page_size == 0: real_return_list = list[0:] else: if ((mount - (page_num - 1) * page_size) / page_size) >= 1 and \ (mount - (page_num * page_size)) > 0: real_return_list = list[((page_num - 1) * page_size):(page_num * page_size)] else: real_return_list = list[((page_num - 1) * page_size):] response = import_status("get_registerinfo_success", "OK") response['data'] = real_return_list response['mount'] = mount return response
def deal_comments(self): if not is_admin(): return TOKEN_ERROR try: data = request.json cmid = data.get('cmid') except: return PARAMS_ERROR result = self.smycenter.deal_comments(cmid) if not result: return SYSTEM_ERROR response = import_status("deal_comment_success", "OK") return response
def delete_commessage(self): if not is_admin(): return AUTHORITY_ERROR try: json_data = request.json messageid = json_data.get('messageid') except Exception as e: return PARAMS_ERROR upate_message = {} upate_message['CMstatus'] = 0 result = self.smessage.delete_commessage(messageid, upate_message) result2 = self.smessage.delete_alreadyread(messageid) response = import_status("delete_message_success", "OK") return response
def delete_sowingmap(self): if not is_admin(): return TOKEN_ERROR try: data = request.json smid = data.get('smid') except: return PARAMS_ERROR if not smid: return PARAMS_MISS result = self.sgoods.update_sowingmap(smid) if not result: return SYSTEM_ERROR response = import_status("delete_sowingmap_success", "OK") return response
def withdraw_product(self): if not is_admin(): return TOKEN_ERROR try: data = request.json prid = data.get('prid') except: return PARAMS_ERROR if not prid: return PARAMS_ERROR result = self.sgoods.withdraw_product(prid) if not result: return SYSTEM_ERROR response = import_status("withdraw_product_success", "OK") return response
def update_pwd(self): if not is_admin(): return AUTHORITY_ERROR json_data = request.json if not json_data: return PARAMS_MISS oldpassword = json_data.get('oldpassword') newpassword = json_data.get('newpassword') user = self.sadmin.getadmin_by_adminid(request.user.id) if not user or user.ADpassword != oldpassword: return PARAMS_ERROR admin_update = {} admin_update["ADpassword"] = newpassword self.sadmin.update_amdin_by_adminid(user.ADid, admin_update) data = import_status("update_password_success", "OK") return data
def add_size(self): if not is_admin(): return TOKEN_ERROR try: data = request.json sizename = data.get("sizename") except Exception as e: print e return PARAMS_ERROR is_same = self.sgoods.get_color_by_sizename(sizename.encode('utf-8')) if is_same: return REPERT_SIZE time_now = datetime.strftime(datetime.now(), format_for_db) result = self.sgoods.add_size(sizename, time_now) if not result: return SYSTEM_ERROR response = import_status("add_size_success", "OK") return response
def add_sowingmap(self): if not is_admin(): return TOKEN_ERROR try: data = request.json type = data['type'] urls = data['urls'] except: return PARAMS_ERROR if int(type) < 0: return PARAMS_ERROR result = self.sgoods.update_sowingmap_by_type(type) if not result: return SYSTEM_ERROR result = self.sgoods.add_sowingmap(type, urls) if not result: return SYSTEM_ERROR response = import_status("add_sowingmap_success", "OK") return response
def update_pwd(self): if not is_admin(): return AUTHORITY_ERROR json_data = request.json if not json_data: return PARAMS_MISS oldpassword = json_data.get('oldpassword') newpassword = json_data.get('newpassword') user = get_model_return_dict( self.sadmin.getadmin_by_adminid(request.user.id)) if not user or not check_password_hash(user['ADpassword'], oldpassword): return PASSWORD_WRONG admin_update = {} admin_update["ADpassword"] = generate_password_hash(newpassword) result = self.sadmin.update_amdin_by_adminid(user['ADid'], admin_update) if not result: return SYSTEM_ERROR data = import_status("update_password_success", "OK") return data
def get_comment_list(self): if not is_admin(): return TOKEN_ERROR try: args = request.args.to_dict() page_num = int(args.get("page_num")) page_size = int(args.get("page_size")) status = int(args.get("status")) except: return PARAMS_ERROR try: comment_list = get_model_return_list( self.smycenter.get_comments(status)) if not comment_list: response = import_status('get_commentslist_success', 'OK') response['data'] = [] response['mount'] = 0 return response for comment in comment_list: comment['CMcreatetime'] = get_web_time_str( comment['CMcreatetime']) mount = len(comment_list) page = mount / page_size if page == 0 or page == 1 and mount % page_size == 0: return_list = comment_list[0:] else: if ((mount - (page_num - 1) * page_size) / page_size) >= 1 and \ (mount - (page_num * page_size)) > 0: return_list = comment_list[((page_num - 1) * page_size):(page_num * page_size)] else: return_list = comment_list[((page_num - 1) * page_size):] response = import_status('get_commentslist_success', 'OK') response['data'] = return_list response['mount'] = mount return response except Exception as e: print e return SYSTEM_ERROR
def publish_commessage(self): if not is_admin(): return AUTHORITY_ERROR try: json_data = request.json type = json_data.get('type') title = json_data.get('title') url = json_data.get('url') except Exception as e: return PARAMS_ERROR if not title or not url: return PARAMS_MISS # 获取当前时间 import datetime from common.timeformat import format_for_db time_time = datetime.datetime.now() time_str = datetime.datetime.strftime(time_time, format_for_db) id = str(uuid.uuid4()) self.smessage.publish_commessage(id, time_str, type, title, url) response = import_status("publish_message_success", "OK") return response
def deal_register_record(self): if not is_admin(): return TOKEN_ERROR try: data = request.json IRIid = data.get('IRIid') willstatus = data.get('willstatus') except: return PARAMS_ERROR info = get_model_return_dict( self.suser.get_registerrecord_by_IRIid(IRIid)) if not info: return NOT_FOUND_USER if willstatus == 2: session = db_session() try: user = self.smycenter.get_user_basicinfo_byphone( info['IRIprephonenum']) # 插入销售表,有数据就更新 if not user: raise dberror user = get_model_return_dict(user) monthnow = datetime.strftime(datetime.now(), format_for_db)[0:6] amount_data = self.saccount.get_user_date( user['USid'], monthnow) if amount_data: amount_data = get_model_return_dict(amount_data) new_data = {} new_data['reward'] = amount_data['reward'] + float( self.conf.get('account', 'reward')) try: session.query(Amount).filter( Amount.USid == user['USid']).update(new_data) except: raise dberror else: amount = Amount() amount.USid = user['USid'] amount.AMid = str(uuid.uuid4()) amount.USagentid = user['USagentid'] amount.USname = user['USname'] amount.reward = float(self.conf.get('account', 'reward')) amount.AMstatus = 1 amount.USheadimg = user['USheadimg'] amount.AMcreattime = datetime.strftime( datetime.now(), format_for_db) amount.AMmonth = datetime.strftime(datetime.now(), format_for_db)[0:6] session.add(amount) new_userid = str(uuid.uuid4()) # 插入新用户 new_user = User() new_user.USid = new_userid new_user.USname = info['IRIname'] new_user.USpre = user['USid'] new_user.USagentid = get_random_str(12) new_user.USheadimg = info['IRIpic'] if info['IRIpic'] else 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_100' \ '00&sec=1540919391&di=91c' \ '1ae656341d5814e63280616ad8ade&imgtype=jpg&er=1&src=http%3A%2F%2Fimg.zcool.cn%2Fcommun' \ 'ity%2F0169d55548dff50000019ae9973427.jpg%401280w_1l_2o_100sh.jpg' new_user.USphonenum = info['IRIphonenum'] new_user.USmount = 0 new_user.USbail = 0 new_user.USwechat = info['IRIwechat'] new_user.idcardnum = info['IRIidcardnum'] new_user.UScreatetime = datetime.strftime( datetime.now(), format_for_db) new_user.USpassword = generate_password_hash( info['IRIpassword']) session.add(new_user) reward = Reward() # 插入直推奖励表 reward.REid = str(uuid.uuid4()) reward.RElastuserid = user['USid'] reward.REnextuserid = new_userid reward.REmonth = datetime.strftime(datetime.now(), format_for_db)[0:6] reward.REmount = float(self.conf.get('account', 'reward')) reward.REcreatetime = datetime.strftime( datetime.now(), format_for_db) session.add(reward) session.query(User).filter(User.USid == user['USid'])\ .update({"USmount": user['USmount'] + float(self.conf.get('account', 'reward'))}) # 写入代理消息 content = u'您推荐的代理已审核通过,直推奖励已发放至余额' agent_result = self.smessage.create_agentmessage( session, user['USid'], datetime.strftime(datetime.now(), format_for_db), content, 2) if not agent_result: return SYSTEM_ERROR USname = info['IRIname'] # 插入默认收货地址 USphonenum = info['IRIphonenum'] USdatails = info['IRIaddress'] areaid = info['IRIarea'] cityid = info['IRIcity'] if areaid: all_areaid = get_model_return_list( self.smycenter.get_all_areaid()) area_list = [] for area in all_areaid: area_list.append(area['areaid']) if areaid not in area_list: return BAD_ADDRESS time_time = datetime.now() time_str = datetime.strftime(time_time, format_for_db) uaid = str(uuid.uuid1()) exist_default = self.smycenter.get_default_address_by_usid( new_userid) uadefault = True if not exist_default else False self.smycenter.add_address_selfsession(session, uaid, new_userid, USname, USphonenum, USdatails, \ areaid, uadefault, time_str, None) else: all_cityid = get_model_return_list( self.smycenter.get_all_cityid()) cityid_list = [] for city in all_cityid: cityid_list.append(city['cityid']) if cityid not in cityid_list: return BAD_ADDRESS time_time = datetime.now() time_str = datetime.strftime(time_time, format_for_db) uaid = str(uuid.uuid1()) exist_default = self.smycenter.get_default_address_by_usid( new_userid) uadefault = True if not exist_default else False self.smycenter.add_address_selfsession(session, uaid, new_userid, USname, USphonenum, USdatails, \ None, uadefault, time_str, cityid) session.commit() except Exception as e: print e session.rollback() return SYSTEM_ERROR finally: session.close() update = {} update['IRIstatus'] = int(willstatus) result = self.suser.update_register_record(IRIid, update) response = import_status("register_success", "OK") return response
def create_update_product(self): if not is_admin(): return AUTHORITY_ERROR params = ['paid', 'prname', 'prpic', 'sowingmap', 'proldprice', 'prprice', 'skulist', 'prlogisticsfee' , 'prdiscountnum', 'prstatus', 'detailpics'] data = request.json for param in params: if param not in data: response = {} response['message'] = u"参数缺失" response['paramname'] = param response['status'] = 405 return response paid = data.get('paid') prname = data.get('prname') prpic = data.get('prpic') proldprice = data.get('proldprice') prprice = data.get('prprice') prlogisticsfee = data.get('prlogisticsfee') prdiscountnum = data.get('prdiscountnum') prstatus = data.get('prstatus') prid = data.get('prid') skulist = data.get('skulist') sowingmap = ",".join(data.get('sowingmap')) detailpics = ",".join(data.get('detailpics')) session = db_session() try: if prid: product = {} product['PAid'] = paid product['PRname'] = prname product['PRpic'] = prpic product['PRoldprice'] = proldprice product['PRprice'] = prprice product['PRlogisticsfee'] = prlogisticsfee product['PRstatus'] = prstatus product['PAdiscountnum'] = prdiscountnum product['sowingmap'] = sowingmap product['detailpics'] = detailpics result = self.sgoods.update_product(session, prid, product) if not result: return SYSTEM_ERROR skuid_list = get_model_return_list(self.sgoods.get_all_skuid(session, prid)) db_skuid_list = [] for id in skuid_list: db_skuid_list.append(id['PSid']) web_skuid_list = [] for sku in skulist: if not sku['psid']: coid = sku['coid'] colorname = sku['colorname'] siid = sku['siid'] sizename = sku['sizename'] stock = sku['stock'] time_now = datetime.strftime(datetime.now(), format_for_db) self.sgoods.create_sku(session, prid, coid, colorname, siid, sizename, stock, time_now) if sku['psid']: web_skuid_list.append(sku['psid']) self.sgoods.update_sku(session, prid, sku['psid'], {'PSstock': sku['stock']}) for dbskuid in db_skuid_list: if dbskuid not in web_skuid_list: session.query(ProductSku).filter(ProductSku.PRid == prid).filter(ProductSku.PSid == dbskuid)\ .update({'PSstatus': 0}) session.commit() response = import_status("update_product_success", "OK") return response else: time_now = datetime.strftime(datetime.now(), format_for_db) prid = str(uuid.uuid4()) result = self.sgoods.create_product(session, prid, paid, prname, prpic, proldprice, prprice , prlogisticsfee, prstatus, prdiscountnum, time_now, sowingmap, detailpics) if not result: return SYSTEM_ERROR for sku in skulist: coid = sku['coid'] colorname = sku['colorname'] siid = sku['siid'] sizename = sku['sizename'] stock = sku['stock'] time_now = datetime.strftime(datetime.now(), format_for_db) self.sgoods.create_sku(session, prid, coid, colorname, siid, sizename, stock, time_now) session.commit() response = import_status("create_product_success", "OK") return response except Exception as e: print e session.rollback() return SYSTEM_ERROR finally: session.close()
def upload_file(self): try: param = request.args.to_dict() type = param.get("type") except: type = None if is_ordirnaryuser() or is_admin(): try: files = request.files.get("file") except: return PARAMS_ERROR if not files: return NOT_FOUND_FILE if platform.system() == "Windows": rootdir = "D:/task" else: rootdir = "/opt/beili/file/" if not os.path.isdir(rootdir): os.makedirs(rootdir) lastpoint = str(files.filename).rindex(".") filessuffix = str(files.filename)[lastpoint + 1:] print 'filessuffix', filessuffix if is_ordirnaryuser(): if filessuffix.lower() in ['png', 'jpg', 'jpeg', 'gif']: image = Image.open(files) w, h = image.size filename = request.user.id + get_db_time_str( ) + get_random_str(6) + "." + filessuffix filepath = os.path.join(rootdir, filename) if type == 1: image.resize((128, 128)).save(filepath) else: image.resize((w / 2, h / 2)).save(filepath) response = import_status("upload_file_success", "OK") url = QRCODEHOSTNAME + "/file/" + filename response["data"] = url return response if is_admin(): if filessuffix.lower() in ['png', 'jpg', 'jpeg', 'gif']: image = Image.open(files) w, h = image.size filename = request.user.id + get_db_time_str( ) + get_random_str(6) + "." + filessuffix filepath = os.path.join(rootdir, filename) # image.resize((w / 2, h / 2)).save(filepath) if w > 1000: image.resize((w * 2 / 3, h * 2 / 3)).save(filepath) else: image.save(filepath) response = import_status("upload_file_success", "OK") url = QRCODEHOSTNAME + "/file/" + filename response["data"] = url return response filename = request.user.id + get_db_time_str() + get_random_str( 6) + "." + filessuffix filepath = os.path.join(rootdir, filename) print(filepath) files.save(filepath) response = import_status("upload_file_success", "OK") url = QRCODEHOSTNAME + "/file/" + filename response["data"] = url return response else: id1 = str(uuid.uuid4()) token = usid_to_token(id=id1, type='Temp') try: files = request.files.get("file") except: return PARAMS_ERROR if not files: return NOT_FOUND_FILE if platform.system() == "Windows": rootdir = "D:/task" else: rootdir = "/opt/beili/file/" if not os.path.isdir(rootdir): os.makedirs(rootdir) lastpoint = str(files.filename).rindex(".") filessuffix = str(files.filename)[lastpoint + 1:] # 后缀名 print filessuffix if filessuffix.lower() in ['png', 'jpg', 'jpeg', 'gif']: image = Image.open(files) w, h = image.size filename = id1 + get_db_time_str() + "." + filessuffix filepath = os.path.join(rootdir, filename) if type == 1: image.resize((128, 128)).save(filepath) else: image.resize((w / 2, h / 2)).save(filepath) url = QRCODEHOSTNAME + "/file/" + filename data = import_status("upload_file_success", "OK") data['data'] = {'token': token, 'url': url} return data filename = id1 + get_db_time_str() + "." + filessuffix filepath = os.path.join(rootdir, filename) print(filepath) files.save(filepath) url = QRCODEHOSTNAME + "/file/" + filename data = import_status("upload_file_success", "OK") data['data'] = {'token': token, 'url': url} return data
def get_willsend_products(self): if not is_admin(): return TOKEN_ERROR # workbook = xlrd.open_workbook(r'/Users/fx/Desktop/项目相关/1.xls') # print (workbook.sheet_names()) # sheet = workbook.sheet_names()[0] # sheet_data = workbook.sheet_by_name(sheet) # print(sheet_data) # print (sheet_data.name, sheet_data.nrows, sheet_data.ncols) # rows = sheet_data.row_values(0) # 获取第一行内容 # cols = sheet_data.col_values(0) # 获取第一列内容 # print (rows) try: data = request.json oisnlist = data.get('oisnlist') except: return PARAMS_ERROR new_oisn_list = [] for oisn in oisnlist: order = get_model_return_dict( self.sorder.get_order_details(str(oisn))) if order['OIstatus'] == 1: new_oisn_list.append(order) style = xlwt.XFStyle() font = xlwt.Font() font.name = u'宋体' font.bold = True style.font = font time_now = datetime.strftime(datetime.now(), format_for_db) workbook = xlwt.Workbook(encoding='utf-8') worksheet = workbook.add_sheet('sheet1') # worksheet.write_merge() worksheet.write(0, 0, label='订单号', style=style) worksheet.write(0, 1, label='收货地址', style=style) worksheet.write(0, 2, label='卖家备注', style=style) worksheet.write(0, 3, label='发件人姓名', style=style) worksheet.write(0, 4, label='发件人电话', style=style) worksheet.write(0, 5, label='发件人地址', style=style) worksheet.write(0, 6, label='发货商品', style=style) font = xlwt.Font() font.name = u'宋体' font.bold = False style.font = font url = '' session = db_session() try: if new_oisn_list: for i, order in enumerate(new_oisn_list): oisn = order['OIsn'] username = order['username'] phone = order['userphonenum'] provincename = order['provincename'] cityname = order['cityname'] areaname = order['areaname'] if order['areaname'] else '' details = order['details'] address = username + ' ' + phone + ' ' + provincename + cityname + areaname + details OInote = order['OInote'] product_list = get_model_return_list( self.sorder.get_product_list(order['OIid'])) productname = self.get_product_name(product_list) worksheet.write(i + 1, 0, label=oisn, style=style) worksheet.write(i + 1, 1, label=address, style=style) worksheet.write(i + 1, 2, label=OInote, style=style) worksheet.write(i + 1, 3, label=self.conf.get('account', 'sendname'), style=style) worksheet.write(i + 1, 4, label=self.conf.get( 'account', 'sendphone'), style=style) worksheet.write(i + 1, 5, label=self.conf.get( 'account', 'sendaddress'), style=style) session.query(OrderInfo).filter( OrderInfo.OIsn == oisn).update({"OIstatus": 4}) worksheet.write(i + 1, 6, label=productname, style=style) if platform.system() == "Windows": rootdir = "D:/task" else: rootdir = "/opt/beili/file/" if not os.path.isdir(rootdir): os.makedirs(rootdir) filename = get_db_time_str() + "." + 'xls' filepath = os.path.join(rootdir, filename) print(filepath) workbook.save(filepath) url = QRCODEHOSTNAME + "/file/" + filename except Exception as e: print e session.rollback() return SYSTEM_ERROR finally: session.commit() response = import_status("get_willsend_products_success", "OK") response['data'] = url return response
def update_order(self): if not is_admin(): return AUTHORITY_ERROR try: data = request.json oisn = data.get('oisn') expressname = data.get('expressname') expressnum = data.get('expressnum') if not expressname or not expressnum: raise dberror except: return PARAMS_ERROR detail = get_model_return_dict(self.sorder.get_order_details(oisn)) if not detail: return NOT_FOUND_ORDER session = db_session() try: is_exits = get_model_return_dict( session.query(OrderInfo.expressnum).filter( OrderInfo.OIsn == oisn).first()) if is_exits['expressnum']: update = {} update['OIstatus'] = 2 update['expressname'] = expressname update['expressnum'] = expressnum session.query(OrderInfo).filter( OrderInfo.OIsn == oisn).update(update) else: update = {} update['OIstatus'] = 2 update['expressname'] = expressname update['expressnum'] = expressnum session.query(OrderInfo).filter( OrderInfo.OIsn == oisn).update(update) monthnow = datetime.strftime(datetime.now(), format_for_db)[0:6] amount_data = self.saccount.get_user_date( detail['USid'], monthnow) order = get_model_return_dict( self.sorder.get_order_details(oisn)) user = self.smycenter.get_user_basicinfo( detail['USid']) # 插入销售表,有数据就更新 if not user: raise dberror user = get_model_return_dict(user) if not order: raise dberror if amount_data: amount_data = get_model_return_dict(amount_data) new_data = {} new_data['performance'] = amount_data[ 'performance'] + order['discountnum'] try: session.query(Amount).filter( Amount.USid == detail['USid']).filter( Amount.AMmonth == monthnow).update(new_data) except: raise dberror else: amount = Amount() amount.USid = detail['USid'] amount.AMid = str(uuid.uuid4()) amount.USagentid = user['USagentid'] amount.performance = order['discountnum'] amount.USname = user['USname'] amount.AMstatus = 1 amount.USheadimg = user['USheadimg'] amount.AMcreattime = datetime.strftime( datetime.now(), format_for_db) amount.AMmonth = monthnow session.add(amount) performance = Performance() # 插入业绩表 performance.USid = detail['USid'] performance.REmonth = datetime.strftime( datetime.now(), format_for_db)[0:6] performance.PEid = str(uuid.uuid4()) performance.PEdiscountnum = order['discountnum'] performance.PEcreatetime = datetime.strftime( datetime.now(), format_for_db) session.add(performance) session.commit() except Exception as e: print e session.rollback() return SYSTEM_ERROR finally: session.close() reponse = import_status("update_order_success", "OK") detail = get_model_return_dict(self.sorder.get_order_details(oisn)) from common.timeformat import get_web_time_str detail['OIcreatetime'] = get_web_time_str(detail['OIcreatetime']) product_list = get_model_return_list( self.sorder.get_product_list(detail['OIid'])) detail['product_list'] = product_list reponse['data'] = detail return reponse
def get_all_order(self): if not is_admin(): return AUTHORITY_ERROR params = [ 'page_size', 'page_num', 'oisn', 'starttime', 'endtime', 'status', 'username', 'userphonenum', 'productname' ] try: data = request.json for param in params: if param not in data: response = {} response['message'] = u"参数缺失" response['paramname'] = param response['status'] = 405 return response except: return PARAMS_ERROR page_size = data.get('page_size') page_num = data.get('page_num') oisn = data.get('oisn') starttime = str(data.get('starttime')) + '000000' if data.get( 'starttime') else None endtime = data.get('endtime') + '000000' if data.get( 'endtime') else None status = data.get('status') username = data.get('username') userphonenum = data.get('userphonenum') productname = data.get('productname') all_order = get_model_return_list( self.sorder.get_all_order(oisn, starttime, endtime, status, username, userphonenum)) return_list = [] for order in all_order: detail = get_model_return_dict( self.sorder.get_order_details(order['OIsn'])) from common.timeformat import get_web_time_str order['OIcreatetime'] = get_web_time_str(order['OIcreatetime']) product_list = get_model_return_list( self.sorder.get_product_list(detail['OIid'])) for product in product_list: product['PRnum'] = 0 sku_list = get_model_return_list( self.sorder.get_sku_list_by_opiid(product['OPIid'])) for sku in sku_list: product['PRnum'] = product['PRnum'] + sku['number'] product['skulist'] = sku_list order['product_list'] = product_list if productname: for product in product_list: if productname in product['PRname']: return_list.append(order) break else: return_list.append(order) mount = len(return_list) page = mount / page_size if page == 0 or page == 1 and mount % page_size == 0: real_return_list = return_list[0:] else: if ((mount - (page_num - 1) * page_size) / page_size) >= 1 and \ (mount - (page_num * page_size)) > 0: real_return_list = return_list[((page_num - 1) * page_size):(page_num * page_size)] else: real_return_list = return_list[((page_num - 1) * page_size):] response = import_status("get_allorder_success", "OK") response['data'] = real_return_list response['mount'] = mount return response