Exemple #1
0
    def get(self):
        last_count = int(self.get_argument('last_count', 0)) #上次加载到第几条
        items_origin = self.db_find_all('User_account', {"user_id": self.user_id, "type": {'$ne': 1}}, ("time", last_count), keepid=True)
        # balance = 0 # 账户余额
        balance = round(User.byid(self, self.user_id, ('balance',)).balance, 2) # 账户余额
        items = []
        for item in items_origin:
            if item['type'] > 0:
                # 根据订单取出商品信息
                order = self.db.Order.find_one({'_id': ObjectId(item['order_id'])})
                if order['status'] != "2":
                    # 只有完成的订单才显示
                    continue

                goods = self.db.Goods.find_one({'_id': ObjectId(order['goods_id'])})
                goods['_id'] = str(goods['_id'])
                item['goods'] = goods

                # 取出用户信息
                hiskey = 'custom_id' if item['type'] == 2 else 'seller_id'
                user = self.db.User.find_one({"_id": ObjectId(order[hiskey])})
                item['user'] = {'nickname': user['nickname'], 'avatar': user['avatar']}

                # 计算余额
                # if item['type'] == 2:
                #     balance += float(goods['price'])
                del item['order_id']
            # else:
            #     balance -= float(item['money'])
            del item['_id']
            del item['user_id']
            items.append(item)
        self.write_success({'balance': balance, 'items': items})
 def get(self):
     hx_name = self.get_argument('hx_name')
     hx_info = self.db.User_extend.find_one({'hx_username': hx_name})
     if hx_info:
         user = User.byid(self, hx_info['user_id'], ('avatar', 'nickname'))
         user.strid()
         self.write_success(user._data)
     else:
         self.write_err('hx_name not found')