def update_permission(self): args = request.args.to_dict() log.info("args", args) data = json.loads(request.data) log.info("data", data) if "token" not in args: return PARAMS_MISS maid = token_to_usid(args.get("token")) manager = self.smanager.get_manager_by_maid(maid) if manager.MAidentity != 100: return get_response("ERROR_MESSAGE_NO_PERMISSION", "MANAGERSYSTEMERROR", "ERROR_CODE_NO_PERMISSION") if "PEid" not in data: return PARAMS_MISS permission = { "PEtype": data.get("PEtype"), "PEsubLevel": data.get("PEsubLevel"), } try: update_result = self.sapproval.update_permission(data.get("PEid"), permission) if not update_result: return get_response("ERROR_MESSAGE_DB_ERROR", "MANAGERSYSTEMERROR", "ERROR_CODE_DB_ERROR") return get_response("SUCCESS_MESSAGE_UPDATE_DATA", "OK") except Exception as e: log.error("update permission", e.message) return SYSTEM_ERROR
def update_manager_by_matel(self): args = request.args.to_dict() log.info("args", args) if "token" not in args: return PARAMS_MISS data = json.loads(request.data) log.info("data", data) if "MAtelphone" not in data: return PARAMS_MISS maid = token_to_usid(args.get("token")) manager = self.smanager.get_manager_by_maid(maid) if manager.MAidentity > 101: return get_response("ERROR_MESSAGE_NO_PERMISSION", "MANAGERSYSTEMERROR", "ERROR_CODE_NO_PERMISSION") try: from ManagerSystem.models.model import Manager mng = { "MAstatus": conversion_MAstatus_resverse.get(get_str(data, "MAstatus")) } update_result = self.smanager.update_users_by_matel( data.get("MAtelphone"), mng) if not update_result: return get_response("ERROR_MESSAGE_DB_ERROR", "MANAGERSYSTEMERROR", "ERROR_CODE_DB_ERROR") return get_response("SUCCESS_MESSAGE_UPDATE_DATA", "OK") except Exception as e: log.error("update users", e.message) return SYSTEM_ERROR
def add_approval(self): args = request.args.to_dict() log.info("args", args) if "token" not in args: return PARAMS_MISS data = json.loads(request.data) log.info("data", data) if "PEtype" not in data or "APcontent" not in data: return PARAMS_MISS petype = conversion_PEtype_resverse.get(get_str(data, "PEtype")) apreceive_list =[apreceive.MAid for apreceive in self.sapproval.get_permission_by_petype_pesublevel(petype, 1)] if not apreceive_list: return get_response("ERROR_MESSAGE_DB_ERROR", "MANAGERSYSTEMERROR", "ERROR_CODE_DB_ERROR") apstart = token_to_usid(args.get("token")) try: apname = get_str(data, "PEtype") + str(uuid.uuid1()) for apreceive in apreceive_list: self.sapproval.add_model("Approval", **{ "APid": str(uuid.uuid1()), "APname": apname, "APstart": apstart, "APstatus": 445, "APreceive": apreceive, "PEtype": petype, "APremark": "", "APcontent": data.get("APcontent"), "APtime": TimeManager.get_db_time_str() }) return get_response("SUCCESS_MESSAGE_ADD_DATA", "OK") except Exception as e: log.error("add approval", e.message) return SYSTEM_ERROR
def update_manager(self): args = request.args.to_dict() log.info("args", args) if "token" not in args: return PARAMS_MISS data = json.loads(request.data) log.info("data", data) if "MAidentity" not in data or "MAstatus" not in data: return PARAMS_MISS manager = {"MAcreatTime": TimeManager.get_db_time_str()} if data.get("MAidentity"): manager["MAidentity"] = conversion_MAidentity_reverse.get( data.get("MAidentity", "卖家")) if data.get("MAstatus"): manager["MAstatus"] = conversion_MAstatus_resverse.get( data.get("MAstatus"), "可用") maid = token_to_usid(args.get("token")) try: self.smanager.update_manager(maid, manager) return get_response("SUCCESS_MESSAGE_GET_INFO", "OK") except Exception as e: log.error("UPDATEERROR", e.message) return SYSTEM_ERROR
def get_stock(self): args = request.args.to_dict() log.info("args", args) params_list = ["token", "STid"] for key in params_list: if key not in args: return PARAMS_MISS maid = token_to_usid(args.get("token")) prid_list = [ product.PRid for product in self.sproduct.get_product_by_maid(maid) ] pbid_list = [] for prid in prid_list: pbid_list.extend([ productbrand.PBid for productbrand in self.sproduct.get_productbrand_by_prid(prid) ]) stocks_list = [] for pbid in pbid_list: stocks_list.extend(tolist(self.sstocks.get_stocks_by_PBid(pbid))) if args.get("STid") not in stocks_list: return get_response("ERROR_MESSAGE_DB_ERROR", "MANAGERSYSTEMERROR", "ERROR_CODE_DB_ERROR") stock = todict(self.sstocks.get_stock_by_stid(args.get("STid"))) response = get_response("SUCCESS_MESSAGE_GET_INFO", "OK") response["data"] = stock return response
def add_category(self): args = request.args.to_dict() log.info("args", args) data = json.loads(request.data) if "token" not in args: return PARAMS_MISS # todo 权限审核 try: maid = token_to_usid(args.get("token")) except: return TOKEN_ERROR ctfromid = "0" if "CTid" in data: ctfromid = get_str(data, "CTid") try: ctid = str(uuid.uuid1()) cateary = { "CTid": ctid, "CTfromid": ctfromid, "MAid": maid, "CTname": data.get("CTname") } self.scategory.add_model("Category", **cateary) except Exception as e: log.error("add category", e.message) return SYSTEM_ERROR
def get_child(self): args = request.args.to_dict() log.info("args", args) if "token" not in args: return PARAMS_MISS ctid = get_str(args, "CTid", "0") if not ctid: ctid = "0" try: category_filter = {Category.CTfromid == ctid} if "category_filter" in args: category_filter.add( Category.CTname.like("%{0}%".format( get_str(args, "category_filter")))) ct_list = tolist( self.scategory.get_category_by_and_filter(category_filter)) log.info("ct_list", ct_list) response = get_response("SUCCESS_MESSAGE_GET_INFO", "OK") response["data"] = ct_list return response except Exception as e: log.error("get child", e.message) return SYSTEM_ERROR
def post(self, category): log.info("get api", category) action = { "add_category": "self.ccategory.add_category()", } if category in action: return eval(action.get(category)) return APIS_WRONG
def post(self, order): log.info("get api", order) action = { "update_order_status": "self.corder.update_order_main()" } if order in action: return eval(action.get(order)) return APIS_WRONG
def get(self, approval): log.info("get api", approval) action = { "get_approval": "self.capproval.get_approval()", } if approval in action: return eval(action.get(approval)) return APIS_WRONG
def post(self, approval): log.info("get api", approval) action = { "add_approval": "self.capproval.add_approval()", "update_approval": "self.capproval.update_approval()" } if approval in action: return eval(action.get(approval)) return APIS_WRONG
def post(self, card): log.info("get api", card) action = { "create": "self.cactive.add_active()", "update_active_status": "self.cactive.update_active_status()" } if card in action: return eval(action.get(card)) return APIS_WRONG
def get(self, stock): log.info("get api", stock) action = { "get_stock_all": "self.cstocks.get_stock_all()", "get_stock": "self.cstocks.get_stock()" } if stock in action: return eval(action.get(stock)) return APIS_WRONG
def dealapproval(self, petypem, APcontent): if petypem == 304: from ManagerSystem.service.SProducts import SProducts spro = SProducts() pb = { "PBstatus": 201 } pb_list = [PB.PBid for PB in spro.get_pbid_by_prid(APcontent)] log.info("len pblist", len(pb_list)) for pbid in pb_list: spro.update_pb(pbid, pb)
def get(self, product): log.info("get api: ", product) apis = { "get_abo": "self.control_product.get_info_by_id()", "get_all": "self.control_product.get_all()", "get_prid": "self.control_product.get_prid()" } if product in apis: return eval(apis[product]) return APIS_WRONG
def post(self, stock): log.info("get api", stock) action = { "add_stock": "self.cstocks.add_stock()", "add_stock_product": "self.cstocks.add_stock_product()", "update_stock": "self.cstocks.update_stock()", "update_stock_product": "self.cstocks.update_stock_product()" } if stock in action: return eval(action.get(stock)) return APIS_WRONG
def get_users(self): args = request.args.to_dict() log.info("args", args) if "token" not in args: return PARAMS_MISS maid = token_to_usid(args.get("token")) try: manager = self.smanager.get_manager_by_maid(maid) if not manager: return SYSTEM_ERROR if manager.MAidentity > 101: return get_response("ERROR_MESSAGE_NO_PERMISSION", "MANAGERSYSTEMERROR", "ERROR_CODE_NO_PERMISSION") page_size = int(args.get("page_size")) page_num = int(args.get("page_num")) or_filter = set() if args.get("USfilter"): from ManagerSystem.models.model import Users or_filter.add( Users.USname.like("%{0}%".format(get_str(args, "USfilter")))) or_filter.add( Users.UStelphone.like("%{0}%".format( get_str(args, "USfilter")))) from ManagerSystem.config.conversion import conversion_USsex pn, count = self.check_page_value(page_num, page_size, "model.Users.USid", set(), or_filter) start_num = (pn - 1) * page_size users = tolist( self.smanager.get_users(start_num, page_size, or_filter)) for user in users: user["USsex"] = conversion_USsex.get(user.get("USsex")) user["UScreateTime"] = TimeManager.get_web_time_str( user.get("UScreateTime")) user["USloginTime"] = TimeManager.get_web_time_str( user.get("USloginTime")) user["USstatus"] = conversion_MAstatus.get( user.get("USstatus")) response = get_response("SUCCESS_MESSAGE_GET_INFO", "OK") response["data"] = { "count": count, "page_num": pn, "page_size": page_size, "USers": users } return response except Exception as e: log.error("get users", e.message) return SYSTEM_ERROR
def get(self, card): log.info("get api", card) action = { "get_all": "self.cactive.get_active()", "get_situation": "self.cactive.get_situation()", "get_acabo": "self.cactive.get_acabo()", } if card in action: return eval(action.get(card)) return APIS_WRONG
def get(self, manager): log.info("get api", manager) action = { "get_manager": "self.cmanager.get_manager()", "get_managers": "self.cmanager.get_managers()", "get_users": "self.cmanager.get_users()", "get_situation": "self.cmanager.get_situation()", } if manager in action: return eval(action.get(manager)) return APIS_WRONG
def post(self, product): log.info("get api :", product) apis = { "release": "self.control_product.add_product()", "update_pro_info": "self.control_product.update_pro_info()", "update_product": "self.control_product.update_product_status()", } if product in apis: return eval(apis[product]) return APIS_WRONG
def get(self, order): log.info("get api", order) action = { "order_list": "self.corder.get_order_list()", "order_abo": "self.corder.get_order_abo()", "get_omfilter": "self.corder.get_omfilter()", "get_order_situation": "self.corder.get_order_situation()", } if order in action: return eval(action.get(order)) return APIS_WRONG
def get(self, category): log.info("get api", category) action = { "get_first": "self.ccategory.get_first()", "get_child": "self.ccategory.get_child()", "get_categorybrands": "self.ccategory.get_categorybrands()", "get_category_by_prname": "self.ccategory.get_category_by_prname()", "get_ctlist_by_ctid": "self.ccategory.get_ctlist_by_ctid()", } if category in action: return eval(action.get(category)) return APIS_WRONG
def update_stock_product(self): args = request.args.to_dict() log.info("args", args) if "token" not in args: return PARAMS_MISS data = json.loads(request.data) log.info("data", data) if "SPid" not in data: return PARAMS_MISS spid = data.get("SPid") sp = {} for key in self.stock_product_key_list: if key not in data: return PARAMS_MISS sp[key] = data.get(key) try: log.info("sp", sp) update_result = self.sstocks.update_stock_product(spid, sp) log.info("update result", update_result) if not update_result: return get_response("ERROR_MESSAGE_DB_ERROR", "MANAGERSYSTEMERROR", "ERROR_CODE_DB_ERROR") return get_response("SUCCESS_MESSAGE_UPDATE_DATA", "OK") except Exception as e: log.error("add stock product error", e.message) return SYSTEM_ERROR
def get_m_by_n(self, key, key_list, brands, brid_list, index): # 首先移除需要判断的key #key_list.remove(key) key_list[index] = 0 len_brid_list = len(brid_list) # 倒序循环,移除不合适的,放跳位 while len_brid_list > 0: # 备份一个brid,用于remove raw = brid_list[len_brid_list - 1] row = brid_list[len_brid_list - 1] log.info("raw", raw) # 循环,直至找到根节点的brid while row != "0": # 获取父节点和当前节点的key、value brand = self.sproduct.get_brand_by_brid(row) print "=================brand=================" print brand print "=================brand=================" # 替代当前值 row, BRkey, BRvalue = brand.BRfromid, brand.BRkey, brand.BRvalue # 判断,如果存在一个key对应的value和实际brands中key对应的value不同,移除当前的brid if BRkey in key_list and brands[BRkey] != BRvalue: brid_list.remove(raw) print "=================BRid_list_remove=================" print brid_list print "=================BRid_list_remove=================" len_brid_list = len_brid_list - 1 # 设置最后要返回的可选值 control_key = [] # 利用已经筛选好的brid_list进行处理 for BRid in brid_list: # 获取key和value brand = self.sproduct.get_brand_by_brid(BRid) BRkey, BRvalue = brand.BRkey, brand.BRvalue # 如果key属于设定的key且value不存在于要返回的list中,那么将value添加进该list if BRkey == key and BRvalue not in control_key: control_key.append(BRvalue) # 否则循环寻找父节点,重复判断逻辑,直到找到对应的key else: while BRid != "0": brand_parent = self.sproduct.get_brand_by_brid(BRid) BRid, BRkey, BRvalue = brand_parent.BRfromid, brand_parent.BRkey, brand_parent.BRvalue if BRvalue not in control_key and BRkey == key: control_key.append(BRvalue) key_list[index] = key return control_key
def get_stock_all(self): args = request.args.to_dict() log.info("args", args) if "token" not in args: return PARAMS_MISS maid = token_to_usid(args.get("token")) try: if "PBid" not in args: prid_list = [ product.PRid for product in self.sproduct.get_product_by_maid(maid) ] log.info("prid list", prid_list) pbid_list = [] for prid in prid_list: pbid_list.extend([ productbrand.PBid for productbrand in self.sproduct.get_productbrand_by_prid(prid) ]) log.info("pbid list", pbid_list) stocks_list = [] for pbid in pbid_list: stock_product_list = tolist( self.sstocks.get_stocks_by_PBid(pbid)) log.info("stock_product_list", stock_product_list) for stock_product in stock_product_list: stock = todict( self.sstocks.get_stock_by_stid( stock_product.get("STid"))) log.info("stock", stock) stock_product.update(stock) stocks_list.extend(stock_product_list) else: stocks_list = tolist( self.sstocks.get_stocks_by_PBid(args.get("PBid"))) for stock_product in stocks_list: stock = todict( self.sstocks.get_stock_by_stid( stock_product.get("STid"))) stock_product.update(stock) response = get_response("SUCCESS_MESSAGE_GET_INFO", "OK") response["data"] = stocks_list return response except Exception as e: log.error("get error", e.message) return SYSTEM_ERROR
def update_product_status(self): args = request.args.to_dict() log.info("args", args) maid = token_to_usid(args.get("token")) if "token" not in args: return PARAMS_MISS data = json.loads(request.data, encoding="utf8") log.info("data", data) if "PRstatus" not in data or "PRid" not in data: return PARAMS_MISS prstatus = get_str(data, "PRstatus") pridlist = data.get("PRid") self.on_or_off_shelves(pridlist, conversion_PBstatus_reverse.get(prstatus), maid) return get_response("SUCCESS_MESSAGE_UPDATE_DATA", "OK")
def get_managers(self): args = request.args.to_dict() log.info("args", args) if "token" not in args: return PARAMS_MISS page_size = int(args.get("page_size")) page_num = int(args.get("page_num")) or_filter = set() if "MAfilter" in args: from ManagerSystem.models.model import Manager or_filter.add( Manager.MAnicname.like("%{0}%".format(get_str( args, "MAfilter")))) or_filter.add( Manager.MAemail.like("%{0}%".format(get_str(args, "MAfilter")))) maid = token_to_usid(args.get("token")) try: pn, count = self.check_page_value(page_num, page_size, "model.Manager.MAid", set(), or_filter) start_num = (pn - 1) * page_size manager = self.smanager.get_manager_by_maid(maid) if not manager: return SYSTEM_ERROR manager_list = tolist( self.smanager.get_managers(start_num, page_size, or_filter)) for manager in manager_list: manager["MAidentity"] = conversion_MAidentity.get( manager.get("MAidentity")) manager["MAstatus"] = conversion_MAstatus.get( manager.get("MAstatus")) manager["MAloginTime"] = TimeManager.get_web_time_str( manager.get("MAloginTime")) manager["MAcreatTime"] = TimeManager.get_web_time_str( manager.get("MAcreatTime")) response = get_response("SUCCESS_MESSAGE_GET_INFO", "OK") response["data"] = { "count": count, "page_num": pn, "page_size": page_size, "Managers": manager_list } return response except Exception as e: log.error("get managers", e.message) return SYSTEM_ERROR
def get_manager(self): args = request.args.to_dict() log.info("args", args) if "token" not in args: return PARAMS_MISS maid = token_to_usid(args.get("token")) try: manager = todict(self.smanager.get_manager_by_maid(maid)) manager["MAstatus"] = conversion_MAstatus.get( manager.get("MAstatus")) manager["MAidentity"] = conversion_MAidentity.get( manager.get("MAidentity")) return manager except Exception as e: log.error("ERROR", e.message) return SYSTEM_ERROR
def on_or_off_shelves(self, prid_list, PBstatus, maid): for prid in prid_list: pbid_list = [pb.PBid for pb in self.sproduct.get_pbid_by_prid(prid)] for pbid in pbid_list: pb = { "PBstatus": PBstatus } # todo 增加审批流 update_result =self.sproduct.update_pb(pbid, pb) log.info("update result", update_result) if not update_result: raise Exception("update pb failed") if PBstatus == 205: self.add_approval(maid, prid)
def post(self, manager): log.info("get api", manager) action = { "apply": "self.cmanager.apply_manager()", "update_manager": "self.cmanager.update_manager()", "update_manager_by_matel": "self.cmanager.update_manager_by_matel()", "update_user": "******", "get_inforcode": "self.cmanager.get_inforcode()", "login": "******", "forget_password": "******", "update_users": "self.cmanager.update_users()", "add_manager": "self.cmanager.add_manager()", } if manager in action: return eval(action.get(manager)) return APIS_WRONG