def auction_buy(self, user_id, auction_id): if not auction_id in self._auction_info: return ng_tool.make_result(-1) auction = self._auction_info[auction_id] user = ng_db.instance().user_get(user_id) if user == None: return ng_tool.make_result(-2) seller_user_id = auction["user_id"] if user_id == seller_user_id: return ng_tool.make_result(-3) cp = self.calc_price(auction["bp"], auction["ep"], auction["duration"], auction["selltime"]) fee = int(cp * 50 / 1000) if cp < fee: cp = fee if user["fish"] < cp: return ng_tool.make_result(-4) ng_dress.instance().dress_transfer_app(auction["dress_id"], user_id) ng_db.instance().user_add_fish(user_id, -cp) sell_price = cp - fee ng_db.instance().user_add_fish(seller_user_id, sell_price) self.cache_auction_del(auction_id) ng_db.instance().auction_delete(auction_id) ng_db.instance().follow_delete_all(auction_id) return ng_tool.make_result(0)
def auction_cancel(self, user_id, auction_id): if not auction_id in self._auction_info: return ng_tool.make_result(-1) auction = self._auction_info[auction_id] if user_id != auction["user_id"]: return ng_tool.make_result(-2) dress_id = auction["dress_id"] self.cache_auction_del(auction_id) ng_db.instance().auction_delete(auction_id) ng_db.instance().follow_delete_all(auction_id) ng_dress.instance().dress_transfer_app(dress_id, user_id) return ng_tool.make_result(0)
def post(self): self.dbug() self._argl = ["user_id", "token", "dress_id"] if not self.check_arguments(): self.end_ex(1) return if not self.check_user(): self.end_ex(2) return res = ng_dress.instance().dress_view(self._args["dress_id"]) self.end(res)
def auction_start(self, user_id, dress_id, bp, ep, duration): bp = int(bp) ep = int(ep) duration = int(duration) dress = ng_dress.instance().cache_dress_get(dress_id) if dress == None or dress["user_id"] != user_id: return ng_tool.make_result(-1) user = ng_db.instance().user_get(user_id) if user == None: return ng_tool.make_result(-2) if bp < 0 or ep < 0 or bp < ep: return ng_tool.make_result(-3) if ep < self.TX_MIN_FEE: return ng_tool.make_result(-3) auction = ng_db.instance().auction_create(dress_id, dress["dress_type"], user_id, user["name"], bp, ep, duration) self.cache_auction_add(user_id, auction) ng_dress.instance().dress_transfer_app(dress_id, "admin") return ng_tool.make_result(0)