예제 #1
0
    def _calc_seek_goods(self, data, req, timer):
        union = data.union.get(True)
        if not union.is_belong_to_target_union(req.index):
            #玩家不属于联盟
            logger.debug("User is not belong to union")
            res = wineShop_pb2.QueryGoodsRes()
            res.status = 0
            res.invalid = True

        else:
            type = ShopInfo.GOODS_TYPE_UNION
            shop_id = ShopInfo.generate_id(data.id, type)
            shop = data.shop_list.get(shop_id)

            goods = []
            if not shop_business.seek_goods(data, [shop], goods, timer.now):
                raise Exception("Seek goods failed")

            resource = data.resource.get(True)
            res = self._pack_refresh_goods_response(goods, shop, resource, req,
                                                    timer.now)

        defer = DataBase().commit(data)
        defer.addCallback(self._seek_goods_succeed, req, res, timer)
        return defer
예제 #2
0
    def _refresh_goods_failed(self, err, req, timer):
        logger.fatal("Refresh goods failed[reason=%s]" % err)

        res = wineShop_pb2.QueryGoodsRes()
        res.status = -1
        response = res.SerializeToString()
        logger.notice(
            "Refresh goods failed[user_id=%d][req=%s][res=%s][consume=%d]" %
            (timer.id, req, res, timer.count_ms()))
        return response
예제 #3
0
    def _pack_refresh_goods_response(self, goods, shop, resource, req, now):
        """打包货物信息
        Args:
            goods[list(GoodsInfo)]: 货物信息
        """
        res = wineShop_pb2.QueryGoodsRes()
        res.status = 0

        for info in goods:
            pack.pack_goods_info(info, res.goods.add())
        res.refresh_num = shop.refresh_num
        res.next_refresh_gap = shop.next_free_time - now
        pack.pack_resource_info(resource, res.resource)
        return res