예제 #1
0
파일: role.go 프로젝트: zhjh1209/a_game
func roleProto(RoleModel *models.RoleData) *protodata.RoleData {

	return &protodata.RoleData{
		RoleId:            proto.Int64(RoleModel.Uid),
		RoleName:          proto.String(RoleModel.Name),
		Stamina:           proto.Int32(int32(RoleModel.ActionValue())),
		MaxStamina:        proto.Int32(int32(models.Role.MaxActionValue)),
		Coin:              proto.Int32(int32(RoleModel.Coin)),
		Diamond:           proto.Int32(int32(RoleModel.Diamond)),
		SuppleStaminaTime: proto.Int32(int32(RoleModel.ActionRecoverTime())),
		SuppleStaDiamond:  proto.Int32(int32(buyActionDiamond(RoleModel.BuyActionNum))),
		KillNum:           proto.Int32(int32(RoleModel.KillNum))}
}
예제 #2
0
파일: http.go 프로젝트: zhjh1209/a_game
func httpConfirm(w http.ResponseWriter, r *http.Request) {

	defer func() {
		if err := recover(); err != nil {
			log.Critical("RPC Panic: %v", err)
		}
	}()

	orderId := r.FormValue("order_id")
	if orderId == "" {
		return
	}

	OrderData, err := models.Order.Order(orderId)
	if err != nil {
		return
	}

	conn := playerMap.Get(OrderData.Uid)

	var RoleData *models.RoleData
	if conn != nil && conn.Role != nil {
		RoleData = conn.Role
	} else {
		RoleData, err = models.Role.Role(OrderData.Uid)
		if err != nil {
			return
		}
	}

	// ----- 启动事务 -----
	if OrderData.Status != 1 {
		log.Warn("Order status not is '1' ORDERID: %s", orderId)
		return
	}

	Transaction, err := models.DB().Begin()
	if err != nil {
		log.Warn("%v", err)
		return
	}

	OrderData.Status = 2

	affected_rows, err := Transaction.Update(OrderData)
	if err != nil || affected_rows != 1 {
		Transaction.Rollback()
		log.Warn("%v", err)
		return
	}

	oldDiamond := RoleData.Diamond
	RoleData.Diamond += OrderData.Diamond
	RoleData.UnixTime = time.Now().Unix()

	_, err = Transaction.Update(RoleData)
	if err != nil {
		RoleData.Diamond = oldDiamond
		Transaction.Rollback()
		log.Warn("%v", err)
		return
	}

	// ----- 提交 -----
	if Transaction.Commit() != nil {
		RoleData.Diamond = oldDiamond
		Transaction.Rollback()
		log.Warn("%v", err)
		return
	}

	models.InsertSubDiamondFinanceLog(OrderData.Uid, models.FINANCE_BUY_DIAMOND, oldDiamond, RoleData.Diamond, fmt.Sprintf("orderId: %s", orderId))

	if conn != nil {
		*conn.Request.CmdId = 10121
		*conn.Request.CmdIndex = 10121
		conn.Send(StatusOK, &protodata.PaySuccessResponse{Role: roleProto(RoleData)})
	}
}