예제 #1
0
    def login(cls, username, password, ip):
        """员工登录"""
        account = StaffAccount.get_account_byusername(username)
        if account is None:
            raise BusinessError("账号或密码错误")

        if password != account.password:
            raise BusinessError("账号或密码错误")

        if account.status == StatusType.LOCK:
            raise BusinessError("该账号已被锁定")

        if account.status == StatusType.DISABLE:
            raise BusinessError("该账号已被禁用")

        account.update(last_login_time=datetime.datetime.now(),
                       status=StatusType.ENABLE)
        record_detail = "{who} 在 {datetime} 登录了系统,登陆 ip: {ip}".format(
            who=account.staff.name,
            datetime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            ip=ip)
        remark = "登录系统"
        JournalMiddleware.register(account.staff, OperationTypes.STAFF, account.staff, \
                       OperationTypes.STAFF, JournalTypes.LOGIN, record_detail, remark)
        return account
예제 #2
0
 def add(cls, **attrs):
     """add new product"""
     if Product.query(name=attrs['name']):
         BusinessError("产品名称已存在")
     product = Product.create(**attrs)
     if not product:
         raise BusinessError("产品添加失败")
예제 #3
0
 def add(cls, **attrs):
     """add new product model"""
     if ProductModel.query(name=attrs['name']):
         BusinessError("产品型号已存在")
     product_id = attrs['product']
     product = Product.get_byid(product_id)
     attrs.update({"product": product})
     product_model = ProductModel.create(**attrs)
     if not product_model:
         raise BusinessError("产品型号添加失败")
예제 #4
0
    def remove(cls, mobile_devices):
        """修改手机设备信息"""
        mobile_phone_qs = MobilephoneServer.searchall(devices = mobile_devices)
        if mobile_phone_qs.count() > 0:
            raise BusinessError("存在手机注册关系无法删除")

        mobile_maintain_qs = MobileMaintainServer.searchall(devices = mobile_devices)
        if mobile_maintain_qs.count() > 0:
            raise BusinessError("存在手机维护关系无法删除")

        return MobileDevicesHelper.remove(mobile_devices)
예제 #5
0
    def get(cls, channel_id):
        """获取渠道详情"""

        channel = Channel.get_byid(channel_id)
        if channel is None:
            raise BusinessError("渠道不存在")
        return channel
예제 #6
0
    def get(cls, service_id):
        """售后服务单信息"""
        service = Service.get_byid(service_id)
        if service is None:
            raise BusinessError("售后服务单不存在")

        return service
예제 #7
0
    def get(cls, service_item_id):
        """售后服务单产品信息"""
        service_item = ServiceItem.get_byid(service_item_id)
        if service_item is None:
            raise BusinessError("售后服务单设备不存在")

        return service_item
예제 #8
0
    def get(cls, order_id):
        """获取渠道详情"""

        order = Order.get_byid(order_id)
        if order is None:
            raise BusinessError("订单不存在")
        return order
예제 #9
0
    def generate(cls, **attrs):
        """添加手机设备"""
        mobiledevices = MobileDevices.create(**attrs)
        if mobiledevices is None:
            raise BusinessError("添加手机设备失败")

        return mobiledevices
예제 #10
0
    def get(cls, sale_chance_id):
        """获取销售机会详情"""

        sale_chance = SaleChance.get_byid(sale_chance_id)
        if sale_chance is None:
            raise BusinessError("销售机会不存在")
        return sale_chance
예제 #11
0
    def get(cls, customer_id):
        """查询客户详情"""

        customer = Customer.get_byid(customer_id)
        if customer is None:
            raise BusinessError("客户不存在")
        return customer
예제 #12
0
    def get(cls, alias_id):
        """获取别名详情"""

        staff_alias = StaffAlias.get_byid(alias_id)
        if staff_alias is None:
            raise BusinessError("别名不存在")
        return staff_alias
예제 #13
0
    def generate(cls, **attrs):
        """添加手机设备维护"""
        mobilemaintain = MobileMaintain.create(**attrs)
        if mobilemaintain is None:
            raise BusinessError("添加手机设备维护失败")

        return mobilemaintain
예제 #14
0
    def get(cls, mobile_phone_id):
        """查询手机信息"""
        mobilephone = Mobilephone.get_byid(mobile_phone_id)
        if mobilephone is None:
            raise BusinessError("此手机不存在")

        return mobilephone
예제 #15
0
    def get(cls, report_id):
        """获取店铺绩效详情"""

        report = MeasureShop.get_byid(report_id)
        if report is None:
            raise BusinessError("店铺绩效不存在")
        return report
예제 #16
0
    def get(cls, measure_staff_id):
        """获取员工绩效详情"""

        measure_staff = MeasureStaff.get_byid(measure_staff_id)
        if measure_staff is None:
            raise BusinessError("员工绩效不存在")
        return measure_staff
예제 #17
0
    def generate(cls, **attrs):
        """添加手机"""
        mobilephone = Mobilephone.create(**attrs)
        if mobilephone is None:
            raise BusinessError("手机添加失败")

        return mobilephone
예제 #18
0
    def generate(cls, **measure_staff_info):
        """创建员工绩效"""

        measure_staff = MeasureStaff.create(**measure_staff_info)
        if measure_staff is None:
            raise BusinessError("员工绩效添加失败")

        return measure_staff
예제 #19
0
 def register(cls, **attrs):
     """创建员工"""
     attrs.update(
         {'password': hashlib.md5("123456".encode("utf-8")).hexdigest()})
     account = StaffAccount.create_byadmin(**attrs)
     if account is None:
         raise BusinessError("员工创建失败")
     return account
예제 #20
0
    def is_name_exist(cls, name):
        """判断员工姓名是否存在"""

        staff = cls.get_staff_byname(name = name)

        if staff is not None:
            raise BusinessError("该名称已存在")
        return True
예제 #21
0
    def get(cls, id):
        """查询设备注册信息"""
        equipment_register = EquipmentRegister.get_byid(id)

        if equipment_register is None:
            raise BusinessError("设备注册信息不存在")

        return equipment_register
예제 #22
0
 def update(cls, **attrs):
     """修改产品信息"""
     if 'name' in attrs:
         name = attrs['name']
         id_qs = [p.id for p in Product.query(name=name)]
         if id_qs and attrs['id'] not in id_qs:
             raise BusinessError("产品名称已存在")
     product = Product().update(**attrs)
     return product
예제 #23
0
    def modify(cls, id, access_id):
        """修改员工绑定的角色或部门"""

        auth_access = AuthAccess.get_byid(id)
        if auth_access is None:
            raise BusinessError("此关系不存在")

        auth_access.update(access_id = access_id)
        return True
예제 #24
0
    def update(cls, measure_staff_id, **attrs):
        """编辑员工绩效"""

        measure_staff = cls.get(measure_staff_id)
        if measure_staff is None:
            raise BusinessError("员工绩效不存在")

        measure_staff.update(**attrs)
        return True
예제 #25
0
    def __init__(self, cur_page, obj_list):
        self.size = 10
        self.cur_page = cur_page
        self.data = None

        if self.cur_page > 0:
            self(obj_list)
        else:
            raise BusinessError("文件页数要求大于0")
예제 #26
0
    def remove(cls, channel_id):
        """移除渠道"""

        channel = cls.get(channel_id)
        shop_qs = ShopServer.search_all(channel=channel)
        if shop_qs.count() > 0:
            raise BusinessError("该渠道下存在店铺,无法删除")
        channel.delete()
        return True
예제 #27
0
    def register_account_bystaff(cls, staff, ip, **account_info):
        """给员工添加账号或修改账号"""
        account_qs = StaffAccount.query(staff=staff)
        if account_qs.count() > 0:
            account = account_qs[0]
            check_username_qs = StaffAccount.query().filter(
                username=account_info["username"]).filter(~Q(id=account.id))
            if check_username_qs.count() > 0:
                raise BusinessError("该账号已存在")
            account.update(**account_info)
        else:
            if cls.get_account_byusername(account_info["username"]):
                if not account_info["password"]:
                    raise BusinessError("密码不能为空")
                account = StaffAccount.create(username = account_info["username"], password = hashlib.md5(account_info["password"].encode("utf-8")).hexdigest(), \
                                              register_ip = ip, staff = staff, status = account_info["status"])

        return account
예제 #28
0
    def remove(cls, mobile_phone_id):
        """删除手机"""

        mobilephone = Mobilephone.get_byid(mobile_phone_id)
        if mobilephone is None:
            raise BusinessError("此手机不存在")

        mobilephone.delete()
        return True
예제 #29
0
 def generate_accout_bystaff(cls, username, staff):
     """根据员工生成账号"""
     password = hashlib.md5("123456".encode("utf-8")).hexdigest()
     account = StaffAccount.create(username=username,
                                   password=password,
                                   staff=staff)
     if account is None:
         raise BusinessError("账号创建失败")
     return account
예제 #30
0
    def generate(cls, **department_info):
        """创建部门"""

        department = Department.create(**department_info)
        if department is None:
            raise BusinessError("部门创建失败")

        department_middleware.force_refresh()
        return department