コード例 #1
0
    def createUser(self, username, password):
        """
            创建账户
        """
        userNum = DBOps.getDocNum(DBCollonfig.users)

        userId = DBCollonfig.startNum + userNum + 1

        now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        # 初始化用户数据
        user = {
            '_id': userId,
            'username': username,
            'password': Encrypt.password_encrypt(password),
            'permissions': {p: 0
                            for p in UserConfig.permissions},
            'createTime': now,
            'createTimeStamp': TimeUtil.time_conversion(now, 1),
            'lastLogin': now,
            # 'department': '',
            'company': '',
            'tel': '',
            'email': '',
            'qq': ''
        }

        DBOps.insertDoc(DBCollonfig.users, user)

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

        return userId
コード例 #2
0
    def handler_function(self):
        args = self.get_request_data()

        now = datetime.now()
        orderId = str(args['userId']) + now.strftime('%Y%m%d%H%M%S')
        nowString = now.strftime('%Y-%m-%d %H:%M:%S')
        order = {
            '_id': orderId,
            'orderId': orderId,
            'userId': args['userId'],
            'title': args['title'],
            'createUser': args['createUser'],
            # 'department': args['department'],
            'company': args['company'],
            'className': args['className'],
            'customerName': args['customerName'],
            'contactName': args['contactName'],
            'expectDate': args['expectDate'],
            'expect': {
                'price': args['price'],
                'tax': args['tax'],
                'num': args['num'],
                'unit': args['unit'],
                'unitNum': args['unitNum'],
                'sumPrice': round(args['sumPrice'], 2),
            },
            'price': args['price'],
            'sumPrice': round(args['sumPrice'], 2),
            'tax': args['tax'],
            'num': args['num'],
            'unit': args['unit'],
            'unitNum': args['unitNum'],
            'desc': args['desc'],
            'createTime': nowString,
            'completeTime': '',
            'paymentTime': '',
            'createTimeStamp': TimeUtil.time_conversion(nowString, 1),
            'completeTimeStamp': 0,
            'paymentTimeStamp': 0,
            'status': 1,
            'evaluation': 0
        }

        DBOps.insertDoc(DBCollonfig.orders, order)

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

        self.response_success()
コード例 #3
0
    def writeLog(cls, userId, action, content=None):
        """
            基础结构
        """
        now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        data = {
            'logTime': now,
            'logTimeStamp': int(
                time.mktime(time.strptime(now, '%Y-%m-%d %H:%M:%S')) * 1000
            ),
            'userId': userId,
            'action': action,
            'contact': content
        }

        DBOps.insertDoc(DBCollonfig.log, data)