Ejemplo n.º 1
0
 def _get_product_into_order_abo(self, pbid):
     product = todict(self.sproduct.get_product_by_pbid(pbid))
     if not product:
         raise Exception("SYSTEM ERROR NO FIDN PBID")
     product.update(
         todict(self.sproduct.get_product_by_prid(product.get("PRid"))))
     product.update(self._get_brinfo(product.get("BRid")))
     product["PBunit"] = cvs.conversion_PBunit.get(
         product.get("PBunit", "其他币种"))
     product["PRbrand"] = cvs.conversion_PRbrand.get(
         product.get("PRbrand"), "其他")
     product["PRtype"] = cvs.conversion_PRtype.get(product.get("PRtype"))
     return product
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
 def get_interface(self, maid):
     mnid_list = [mm.MNid for mm in self.sinterface.get_mnid_by_maid(maid)]
     menu_dict = {}
     for mnid in mnid_list:
         menu = todict(self.sinterface.get_menu_by_mnid(mnid))
         parentid = menu.get("MNparent")
         while parentid != "0":
             if parentid in menu_dict:
                 menu_dict[parentid].append(menu)
             else:
                 menu_dict[parentid] = [menu]
             menu = todict(self.sinterface.get_menu_by_mnid(parentid))
             if not menu:
                 raise Exception("SYSTEM ERROR")
             parentid = menu.get("MNparent")
     log.info("menu dict", menu_dict)
     menu_list = []
     for mnid in menu_dict:
         menu = todict(self.sinterface.get_menu_by_mnid(mnid))
         menu["children"] = menu_dict.get(mnid)
         menu_list.append(menu)
     log.info("menu list", menu_list)
     return menu_list
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
    def _get_brinfo(self, brid):
        brinfo = {}
        while True:
            brand = todict(self.sproduct.get_brand_by_brid(brid))
            if not (brand.get("BRkey") and brand.get("BRvalue")):
                error = "the brand does not have BRkey or BRvalue. brand = {0}".format(
                    brand)
                raise Exception(error)

            if brand.get("BRkey") in brinfo:
                raise Exception(
                    "the product has duplicate brand = {0}".format(brand))

            brinfo[brand.get("BRkey")] = brand.get("BRvalue")

            if brand.get("BRfromid") == "0":
                break
            brid = brand.get("BRfromid")

        return brinfo
Ejemplo n.º 7
0
    def _get_order_abo_by_order_main(self, order_main):
        order_part_list = tolist(
            self.sorder.get_order_part_list_by_omid(order_main.get("OMid")))
        for order_part in order_part_list:
            order_part.update(
                self._get_product_into_order_abo(order_part.get("PBid")))

        order_main["order_abo"] = order_part_list
        order_main["OMcointype"] = cvs.conversion_PBunit.get(
            order_main.get("OMcointype"), "其他币种")
        order_main["OMstatus"] = cvs.conversion_OMstatus.get(
            order_main.get("OMstatus"), 0)
        order_main["OMtime"] = TimeManager.get_web_time_str(
            order_main.get("OMtime"))
        location = todict(
            self.sorder.get_location_by_loid(order_main.get("LOid")))
        if location.get("LOisedit") == 303:
            print(get_response("ERROR_MESSAGE_GET_LOCATION",
                               "WORING_LOCATION"))
        order_main.update(location)
        order_main["CAid"] = order_main.pop("COid")
Ejemplo n.º 8
0
    def get_order_abo(self):
        try:
            args = request.args.to_dict()
            log.info("args", args)
            if "token" not in args or "OMid" not in args:
                return PARAMS_MISS

            maid = token_to_usid(args.get("token"))
            if not maid:
                return TOKEN_ERROR

            order_main = todict(
                self.sorder.get_order_main_by_om_id(get_str(args, "OMid")))
            order_main.pop("USid")

            self._get_order_abo_by_order_main(order_main)
            log.info("order main", order_main)
            data = get_response("SUCCESS_MESSAGE_GET_INFO", "OK")
            data["data"] = order_main
            return data
        except Exception as e:
            log.error("get order abo", e.message)
            return SYSTEM_ERROR
Ejemplo n.º 9
0
    def update_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)
        params = ["APid",  "APaction", 'APremark']
        for key in params:
            if key not in data:
                return PARAMS_MISS
        try:
            maid = token_to_usid(args.get("token"))
        except:
            return TOKEN_ERROR
        try:
            approval = todict(self.sapproval.get_approval_by_apid(data.get("APid")))
            log.info("approval", approval)

            petype = approval.get("PEtype")
            apaction = get_str(data, "APaction")

            pemaxlevel = self.sapproval.get_max_level(petype)
            log.info("max level", pemaxlevel)
            permission = self.sapproval.gert_pemission_by_maid_petype(maid, petype)
            log.info("permission", permission)

            manager = todict(self.smanager.get_manager_by_maid(maid))
            apremark = get_str(approval, "APremark", "") + "\n" + get_str(manager, "MAname") + ":\n" + get_str(data, "APremark", "")
            log.info("apremark", apremark)
            update_approval = {
                "APid": str(uuid.uuid1()),
                "APname": approval.get("APname"),
                "APremark": apremark,
                "APstart": approval.get("APstart"),
                "APtime": approval.get("APtime"),
                "APcontent": approval.get("APcontent"),
                "PEtype": approval.get("PEtype")
            }
            recevie_list = []
            if apaction == "同意":
                if pemaxlevel == permission.PEsubLevel:
                    update_approval["APstatus"] = 445
                    self.dealapproval(petype, data.get("APcontent"))
                    self.sapproval.update_approval_by_name(approval.get("APname"), {"APstatus": 445, "APremark": apremark})

                else:
                    update_approval["APstatus"] = 443
                    self.sapproval.update_approval_by_name(approval.get("APname"), {"APstatus": 442, "APremark": apremark})
                    recevie_list = self.sapproval.get_permission_by_petype_pesublevel(petype, permission.PEsubLevel + 1)

            else:
                update_approval["APstatus"] = 444
                update_approval["APreceive"] = approval.get("APstart")
                self.sapproval.update_approval_by_name(approval.get("APname"), {"APstatus": 444, "APremark": apremark})

            if recevie_list:
                for recevie in recevie_list:
                    update_approval["APreceive"] = recevie.MAid
                    self.sapproval.add_model("Approval", **update_approval)
            else:
                self.sapproval.add_model("Approval", **update_approval)

            return get_response("SUCCESS_MESSAGE_UPDATE_DATA", "OK")
        except Exception as e:
            log.error("update approval", e.message)
            return SYSTEM_ERROR
Ejemplo n.º 10
0
    def get_order_list(self):
        try:
            args = request.args.to_dict()
            log.info("args", args)
            if "token" not in args or "page_size" not in args or "page_num" not in args:
                return PARAMS_MISS
            page_size = int(args.get("page_size"))
            page_num = int(args.get("page_num"))
            maid = token_to_usid(args.get("token"))
            from ManagerSystem.models.model import Products
            product_filter = {Products.MAid == maid}
            if args.get("PRname"):
                product_filter.add(
                    Products.PRname.like("%{0}%".format(get_str(
                        args, "PRname"))))

            product_list = tolist(
                self.sproduct.get_product_by_filter(product_filter))
            log.info("product list ", product_list)
            pb_list = []
            for product in product_list:
                product["PBunit"] = cvs.conversion_PBunit.get(
                    product.get("PBunit", "其他币种"))
                product["PRbrand"] = cvs.conversion_PRbrand.get(
                    product.get("PRbrand"), "其他")
                product["PRtype"] = cvs.conversion_PRtype.get(
                    product.get("PRtype"))
                for pb in tolist(
                        self.sproduct.get_pball_by_prid(product.get("PRid"))):
                    pb.update(product)
                    pb_list.append(pb)
            log.info("pb_list", pb_list)
            om_list = []
            om_id_dict = {}
            from ManagerSystem.models.model import OrderMain
            omfilter = set()
            if args.get("OMstatus"):
                omstatus = cvs.conversion_OMstatus_reverse.get(
                    get_str(args, "OMstatus"))
                omfilter.add(OrderMain.OMstatus == omstatus)
            if args.get("OMlogisticsName"):
                omfilter.add(OrderMain.OMlogisticsName == get_str(
                    args, "OMlogisticsName"))
            if args.get("OMstartTime"):
                omfilter.add(OrderMain.OMtime >= TimeManager.get_db_time_str(
                    args.get("OMstartTime")))
            if args.get("OMendTime"):
                omfilter.add(OrderMain.OMtime <= TimeManager.get_db_time_str(
                    args.get("OMendTime")))

            for pb in pb_list:
                op_pb_list = tolist(
                    self.sorder.get_order_part_list_by_pbid(pb.get("PBid")))
                for op_pb in op_pb_list:
                    op_pb.update(pb)
                    if op_pb.get("OMid") in om_id_dict:
                        om_id_dict[op_pb.get("OMid")].append(op_pb)
                    else:
                        om_id_dict[op_pb.get("OMid")] = [op_pb]
            log.info("om_id_dict", om_id_dict)
            om_count = {k: 0 for k in cvs.conversion_OMstatus}
            for om_id in om_id_dict:
                if args.get("OMid") and args.get("OMid") not in om_id:
                    continue
                omfilter_tmp = omfilter.copy()
                omfilter_tmp.add(OrderMain.OMid == om_id)
                om_dict = tolist(self.sorder.get_om_by_filter(omfilter_tmp))
                if not om_dict:
                    continue
                om_dict = om_dict[0]
                om_dict.update({"order_item": om_id_dict.get(om_id)})
                location = todict(
                    self.sorder.get_location_by_usid(om_dict.pop("USid")))
                log.info("location", location)
                om_count[om_dict.get("OMstatus")] += 1
                om_dict.update(location)
                om_dict["OMcointype"] = cvs.conversion_PBunit.get(
                    om_dict.get("OMcointype"), "其他币种")
                om_dict["OMstatus"] = cvs.conversion_OMstatus.get(
                    om_dict.get("OMstatus"), 0)
                om_dict["OMtime"] = TimeManager.get_web_time_str(
                    om_dict.get("OMtime"))

                om_list.append(om_dict)
            log.info("omlist", om_list)
            count = len(om_list)
            if page_size * page_num > count:
                page_num = count / page_size + 1
            page_num = page_num if page_num > 0 else 1
            om_list = om_list[(page_num - 1) * page_size:page_num * page_size]
            data = get_response("SUCCESS_MESSAGE_GET_INFO", "OK")
            data["data"] = {
                "count": count,
                "page_num": page_num,
                "page_size": page_size,
                "OrderMains": om_list,
                "OMcount": om_count
            }
            return data
        except Exception as e:
            log.error("get order list", e.message)
            import traceback
            print(traceback.format_exc())
            return SYSTEM_ERROR
Ejemplo n.º 11
0
    def get_all(self):
        args = request.args.to_dict()
        log.info("args", args)
        if "token" not in args or "page_size" not in args or "page_num" not in args:
            return PARAMS_MISS
        page_size = int(args.get("page_size"))
        page_num = int(args.get("page_num"))
        maid = token_to_usid(args.get("token"))
        from ManagerSystem.models.model import Products
        pro_fillter = {Products.MAid == maid}
        sub_filter = set()
        if args.get("product_filter"):
            product_filter = get_str(args, "product_filter")
            sub_filter = {
                Products.PRname.like("%{0}%".format(product_filter)),
                Products.PRinfo.like("%{0}%".format(product_filter))
            }

        pn, count = self.check_page_value(page_num, page_size, "model.Products.PRid", pro_fillter, sub_filter)
        start_num = (pn - 1) * page_size
        PRid_list = [products.PRid for products in self.sproduct.get_all_prid(start_num, page_size, pro_fillter, sub_filter)]
        log.info("PRid list", PRid_list)
        pbstatus = get_str(args, "PBstatus")
        # todo 增加遍历输出所有图片
        # htv = float(args.get("htv", 0.48))
        # from ManagerSystem.common.Gethdp import get_hdp
        # hdp = get_hdp(htv)
        product_infos = []
        for PRid in PRid_list:
            product = todict(self.sproduct.get_product_by_prid(PRid))
            log.info("product", product)
            if not product:
                return SYSTEM_ERROR

            product["PRid"] = PRid
            product["PRimage"] = json.loads(product.get("PRimage"))
            product["PRaboimage"] = json.loads(product.get("PRaboimage"))
            product["PRtype"] = conversion_PRtype.get(get_str(product, "PRtype"))
            product["PRtime"] = TimeManager.get_web_time_str(product.get("PRtime"))
            product["PRbrand"] = json.loads(product.get("PRbrand"))
            log.info("pbstatus", pbstatus)
            saleamount = 0
            stockamout = 0
            if not pbstatus:
                pb_list = tolist(self.sproduct.get_pball_by_prid(PRid))
            else:
                pb_list = tolist(self.sproduct.get_pball_by_prid_pbstatus(PRid, conversion_PBstatus_reverse.get(pbstatus)))

            PRstatus = ""
            for pb in pb_list:
                saleamount += int(pb.get("PBsalesvolume"))
                PRstatus = conversion_PBstatus.get(pb.get("PBstatus"))
                stockamout += sum([int(st.get("PBnumber", 0)) for st in tolist(self.stock.get_stocks_by_PBid(pb.get("PBid")))])
                pb.update(product)

            if not PRstatus:
                count -= 1
                continue

            # product_infos.extend(pb_list)
            product["PRsalesvolume"] = saleamount
            product["PRstock"] = stockamout
            product["PRstatus"] = PRstatus
            product_infos.append(product)

        response_of_product = get_response("SUCCESS_MESSAGE_GET_INFO", "OK")
        response_of_product["data"] = {
            "count": count,
            "page_num": page_num,
            "page_size": page_size,
            "products": product_infos
        }
        log.info("response", response_of_product)
        return response_of_product