Exemplo n.º 1
0
    def handler_function(self):
        args = self.get_request_data()

        userId = args['userId']

        user = DBOps.getOneDoc(DBCollonfig.users, {'_id': userId},
                               {'orders': 0})

        companies = DBOps.getOneDoc(DBCollonfig.options,
                                    {'_id': DBCollonfig.orderOption},
                                    {'companies': 1})['companies']

        user['setPermissions'] = [
            k for k, v in user['permissions'].iteritems() if v == 1
        ]

        user['pmsListName'] = [
            UserConfig.permissions[k]
            for k, v in user['permissions'].iteritems() if v == 1
        ]

        self.result['result'] = {
            'user':
            user,
            'companies': [{
                'label': c['name'],
                'value': c['name']
            } for c in companies],
            'permissions': [{
                'key': k,
                'label': v
            } for k, v in UserConfig.permissions.iteritems()],
        }
        self.response_success()
Exemplo n.º 2
0
    def handler_function(self):
        orderOptions = DBOps.getOneDoc(
            DBCollonfig.options,
            {'_id': DBCollonfig.orderOption},
            {'workClasses': 0}
        )
        classes = orderOptions['classes']
        customers = orderOptions['customers']
        contacts = orderOptions['contacts']
        companies = orderOptions['companies']
        helpInfo = orderOptions['helpInfo']

        self.result['result'] = {
            'classes': [
                {'label': cl['name'], 'value': cl['name']} for cl in classes
            ],
            'customers': [
                {'label': cu['name'], 'value': cu['name']} for cu in customers
            ],
            'contacts': [
                {
                    'label': con['name'] + ' | ' + con['workClass'],
                    'value': con['name']
                } for con in contacts
            ],
            'companies': [
                {'label': com['name'], 'value': com['name']}
                for com in companies
            ],
            'helpInfo': helpInfo
        }

        return self.response_success()
Exemplo n.º 3
0
    def handler_function(self):
        args = self.get_request_data()

        userId = AuthenticationUtil.getUserIdByToken(self.request)

        startDate, endDate, searchParams = self.getSearchParams(args['search'])

        orders = None
        if args['orderListType'] == 'self':
            searchParams.update({'userId': userId})
            orders = DBOps.getSomeDoc(DBCollonfig.orders, searchParams)
        elif args['orderListType'] == 'company':
            company = DBOps.getOneDoc(
                DBCollonfig.users,
                {'_id': userId},
                {'company': 1}
            )['company']
            searchParams.update({'company': company})
            orders = DBOps.getSomeDoc(DBCollonfig.orders, searchParams)
        elif args['orderListType'] == 'summary':
            orders = DBOps.getSomeDoc(DBCollonfig.orders, searchParams)

        self.result['result'] = {
            'orders': list(orders.sort('createTimeStamp', -1)),
            'searchDate': [startDate.split(' ')[0], endDate.split(' ')[0]],
            'totalCount': orders.count()
        }
        return self.response_success()
Exemplo n.º 4
0
    def handler_function(self):
        args = self.get_request_data()
        token = args.get('token', None)

        if token:
            setToken, header = Authentication.getVerifyToken(token)
            if setToken.has_key('userId'):
                userId = setToken['userId']
                user = DBOps.getOneDoc(DBCollonfig.users, {'_id': userId})

                DBOps.setOneDoc(DBCollonfig.users, {'_id': user['_id']}, {
                    '$set': {
                        'lastLogin':
                        datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                    }
                })

                self.result['result'] = {
                    'userObj': AccountUtil.resUserData(user)
                }

                return self.response_success()
            else:
                self.result['result'] = {'userObj': None}
                return self.response_failure(u'登录过期')
        else:
            self.result['result'] = {'userObj': None}
            return self.response_failure(u'没有登录')
Exemplo n.º 5
0
    def handler_function(self):
        args = self.get_request_data()

        username = args['username']
        password = args['password']

        user = DBOps.getOneDoc(DBCollonfig.users, {'username': username})

        if not user:
            return self.response_failure(username + u'用户不存在')

        if user['password'] != Encrypt.password_encrypt(password):
            return self.response_failure(username + u'用户密码错误')

        DBOps.setOneDoc(DBCollonfig.users, {'_id': user['_id']}, {
            '$set': {
                'lastLogin': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            }
        })

        self.result['result'] = {
            'userObj': AccountUtil.resUserData(user),
            'token': Authentication.generateToken(user['_id'])
        }

        # 记录日志
        LogDBOps.writeLog(user['_id'], LogDBConfig.doLogin)

        return self.response_success()
Exemplo n.º 6
0
    def handler_function(self):
        args = self.get_request_data()
        username = args.get('username', None)
        password1 = args.get('password1', None)
        password2 = args.get('password2', None)
        key = args.get('registerKey', None)

        if key != 'szx2018':
            return self.response_failure(username + u'验证码错误')

        if password1 != password2:
            return self.response_failure(username + u'两次密码不一致')

        if re.findall(' ', username):
            return self.response_failure(u'账号不能有空格符号')

        if re.findall(' ', password1):
            return self.response_failure(u'密码不能有空格符号')

        user = DBOps.getOneDoc(DBCollonfig.users, {'username': username})

        if user:
            return self.response_failure(username + u'用户已存在')

        userId = self.createUser(username, password1)

        # 记录日志
        LogDBOps.writeLog(userId, LogDBConfig.doRegister)
        LogDBOps.writeLog(userId, LogDBConfig.doLogin)

        self.response_success()
Exemplo n.º 7
0
    def handler_function(self):
        args = self.get_request_data()

        customerData = DBOps.getOneDoc(DBCollonfig.options, {
            '_id': DBCollonfig.orderCustomer,
            'contacts.name': args['contactName']
        }, {'contacts.$': 1})
        if customerData:
            self.result['result'] = customerData['contacts'][0]
            self.response_success()
        else:
            self.response_failure(msg=u'该外包已删除')
Exemplo n.º 8
0
    def handler_function(self):
        departments = DBOps.getOneDoc(DBCollonfig.options,
                                      {'_id': DBCollonfig.orderOption},
                                      {'departments': 1})['departments']

        self.result['result'] = {
            'departments': [{
                'label': d['name'],
                'value': d['name']
            } for d in departments]
        }

        return self.response_success()
Exemplo n.º 9
0
    def handler_function(self):
        args = self.get_request_data()

        createUser = args.get('createUser', None)
        newContacts = args.get('contacts', None)

        error_list = []
        for each in newContacts:
            isExist = DBOps.getOneDoc(
                DBCollonfig.options,
                {
                    '_id': DBCollonfig.orderOption,
                    'contacts.name': each['name']
                }
            )
            if isExist:
                error_list.append(each['name'])

        if error_list:
            msg = u','.join([err for err in error_list]) + u'已存在'
            return self.response_failure(msg=msg)

        for each in newContacts:
            DBOps.setOneDoc(
                DBCollonfig.options,
                {'_id': DBCollonfig.orderOption},
                {
                    '$push': {
                        'contacts': {
                            'name': each['name'],
                            'realName': each['realName'],
                            'createTime': TimeUtil.time_conversion(
                                each['time'], 2
                            ),
                            'createTimeStamp': each['time'],
                            'createUser': createUser,
                            'tel': each['tel'],
                            'email': each['email'],
                            'qq': each['qq'],
                            'payInfo': each['payInfo'],
                            'workClass': each['workClass']
                        }
                    }
                }
            )

        # 记录日志
        LogDBOps.writeLog(args['opsUserId'], LogDBConfig.doCreateContact)

        return self.response_success()
Exemplo n.º 10
0
    def handler_function(self):
        args = self.get_request_data()

        initData = DBOps.getOneDoc(
            DBCollonfig.options,
            {'_id': DBCollonfig.orderOption},
            {args['optionType']: 1}
        )[args['optionType']]

        if args['optionType'] == 'contacts':
            self.result['result'] = self.initContactsData(args, initData)
        elif args['optionType'] == 'customers':
            self.result['result'] = self.initCustomersData(args, initData)
        else:
            self.result['result'] = OrderUtil.orderListByTime(initData)
        return self.response_success()
Exemplo n.º 11
0
    def initContactsData(self):
        """
            初始化外包信息
        """
        contacts = DBOps.getOneDoc(
            DBCollonfig.options,
            {'_id': DBCollonfig.orderContact},
            {'contacts': 1}
        )['contacts']

        for contact in contacts:
            realName = contact['realName']
            payInfo = contact['payInfo']
            self.contacts[contact['name']] = {
                'realName': realName if realName else u'未设置',
                'payInfo': payInfo if payInfo else u'未设置'
            }
Exemplo n.º 12
0
    def initContactsData(self, args, initData):
        """
            初始化外包人员信息
        """

        # 搜索删选
        keyName = args['keyName']
        workClass = args['workClass']
        orderContacts = OrderUtil.orderListByTime(initData)

        if keyName or workClass:
            try:
                totalContacts = [
                    o for o in orderContacts
                    if re.match(r'.*' + keyName + '.*', o['name']) and \
                       re.match(workClass, o['workClass'])
                ]
            except Exception as e:
                totalContacts = []
        else:
            totalContacts = orderContacts

        # 分页处理
        page = args['page']
        pageSize = OrderConfig.optionPageSize
        pageStart = (page - 1) * pageSize
        pageEnd = page * pageSize
        contacts = totalContacts[pageStart:pageEnd]

        workClasses = DBOps.getOneDoc(
            DBCollonfig.options,
            {'_id': DBCollonfig.orderOption},
            {'workClasses': 1}
        )['workClasses']

        return {
            'contacts': contacts,
            'totalCount': len(totalContacts),
            'pageSize': OrderConfig.optionPageSize,
            'workClasses': [
                {'label': w['name'], 'value': w['name']}
                for w in workClasses
            ],
        }
Exemplo n.º 13
0
    def handler_function(self):
        args = self.get_request_data()
        option = args['option']
        createUser = args['createUser']
        now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        if args['optionType'] == 'contacts':
            oldContact = DBOps.getOneDoc(
                DBCollonfig.options,
                {
                    '_id': DBCollonfig.orderContact,
                    'contacts.name': option['oldName']
                }
            )
            if not oldContact:
                return self.response_failure(msg=u'外包人员不存在')
            DBOps.setOneDoc(
                DBCollonfig.options,
                {
                    '_id': DBCollonfig.orderContact,
                    'contacts.name': option['oldName']
                },
                {
                    '$set': {
                        'contacts.$.name': option['name'],
                        'contacts.$.realName': option['realName'],
                        'contacts.$.tel': option['tel'],
                        'contacts.$.email': option['email'],
                        'contacts.$.workClass': option['workClass'],
                        'contacts.$.payInfo': option['payInfo'],
                        'contacts.$.qq': option['qq'],
                        'contacts.$.createUser': createUser,
                        'contacts.$.createTime': now,
                        'contacts.$.createTimeStamp': TimeUtil.time_conversion(
                            now, 1
                        ),
                    }
                }
            )

            # 记录日志
            LogDBOps.writeLog(args['opsUserId'], LogDBConfig.doEditContact)

            return self.response_success()
        elif args['optionType'] == 'customers':
            DBOps.setOneDoc(
                DBCollonfig.options,
                {
                    '_id': DBCollonfig.orderCustomer,
                    'customers.name': option['name']
                },
                {
                    '$set': {
                        'customers.$.billInfo': option['billInfo'],
                        'customers.$.mailAddress': option['mailAddress'],
                        'customers.$.createUser': createUser,
                        'customers.$.createTime': now,
                        'customers.$.createTimeStamp': TimeUtil.time_conversion(
                            now, 1
                        ),
                    }
                }
            )

            # 记录日志
            LogDBOps.writeLog(args['opsUserId'], LogDBConfig.doEditCustomer)

            return self.response_success()
        else:
            return self.response_failure(msg=u'没有需要修改的信息')
Exemplo n.º 14
0
    def handler_function(self):
        args = self.get_request_data()

        setStatus = args.get('status', None)
        orderId = args.get('orderId', None)

        nowStatus = DBOps.getOneDoc(
            DBCollonfig.orders,
            {'_id': orderId}
        )['status']

        if nowStatus == setStatus:
            return self.response_failure(msg='订单状态已被修改!')

        logAction = None

        nowString = datetime.now().strftime(DATETIME_FORMAT)
        setParams = {}
        if setStatus == 1:
            setParams = self.setStatus1(setStatus, args)
            logAction = LogDBConfig.doEditOrder
            if args['opsUserId'] != args['userId']:
                content = {
                    'status': setStatus,
                    'sendUserId': args['opsUserId'],
                    'rcvUserId': args['userId'],
                    'orderTitle': args['title'],
                    'createUser': args['createUser']
                }
                AccountMsg.setOrderMsg(content)

        elif setStatus == 2:
            setParams = self.setStatus2(setStatus, nowString, args)
            logAction = LogDBConfig.doCompleteOrder
            content = {
                'status': setStatus,
                'sendUserId': args['opsUserId'],
                'rcvUserId': 'summaryUser',
                'orderTitle': args['title'],
                'createUser': args['createUser']
            }
            AccountMsg.setOrderMsg(content)

        elif setStatus == 3:
            setParams = self.setStatus3(setStatus, nowString, args)
            logAction = LogDBConfig.doPaymentOrder
            if args['opsUserId'] != args['userId']:
                content = {
                    'status': setStatus,
                    'sendUserId': args['opsUserId'],
                    'rcvUserId': args['userId'],
                    'orderTitle': args['title'],
                    'createUser': args['createUser']
                }
                AccountMsg.setOrderMsg(content)

        DBOps.setOneDoc(
            DBCollonfig.orders,
            {'_id': orderId},
            {'$set': setParams}
        )

        # 记录日志
        LogDBOps.writeLog(args['opsUserId'], logAction)
        self.result['result'] = {'opsTime': nowString}
        return self.response_success(msg='订单状态修改成功!')